在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
/** * 写excel方法 */ function writeExcel($tabArr, $dataArr,$path) { require_once CODE_BASE2 . '/util/phpexcel/PHPExcel.php'; $objPHPExcel = new PHPExcel(); $objSheet = $objPHPExcel->setActiveSheetIndex(0); //写表头 $index = 'A'; foreach ($tabArr as $value) { $objSheet->setCellValue($index .'1', $value); $index++; } //写数据 $i = 2; foreach ($dataArr as $key => $line) { $index = 'A'; foreach($line as $val){ $objSheet->setCellValue($index.$i, $val); $index++; } $i++; } $objWriter = PHPExcel_IOFactory:: createWriter($objPHPExcel, 'Excel2007'); $objWriter->save($path); } //php 读取excel function readExcel($path){ require_once CODE_BASE2 . '/util/phpexcel/PHPExcel.php'; $reader = PHPExcel_IOFactory::createReader('Excel5'); //设置以Excel5格式(Excel97-2003工作簿) $PHPExcel = $reader->load($path); // 载入excel文件 $sheet = $PHPExcel->getSheet(0); // 读取第一個工作表 $highestRow = $sheet->getHighestRow(); // 取得总行数 $highestColumm = $sheet->getHighestColumn(); // 取得总列数 $res=array(); /** 循环读取每个单元格的数据 */ for ($row = 1; $row <= $highestRow; $row++){//行数是以第1行开始 for ($column = 'A'; $column <= $highestColumm; $column++) {//列数是以A列开始 $res[$row-1][] = $sheet->getCell($column.$row)->getValue(); } } return $res; }
|
2022-08-18
2022-07-18
2022-08-17
2022-08-17
2022-11-06
请发表评论