This article mainly introduces the method of modifying existing Excel with PHPExcel. It has certain reference value. Now I share it with you. Friends in need can refer to it
as follows Display:
require_once './Classes/PHPExcel/IOFactory.php'; $filePath = './Template.xlsx'; //读取文件 if (!file_exists($filePath)) { exit("you dont have "); } $objPHPExcel = PHPExcel_IOFactory::load($filePath); $sheet = $objPHPExcel->getSheet(0); // 读取第一個工作表 $highestColumm = $sheet->getHighestColumn(); // 取得总列数 $highestRow = $sheet->getHighestRow(); // 取得总行数 /** 循环读取每个单元格的数据 */ $i = 2; foreach ($list as $key => $value) { $objPHPExcel->setActiveSheetIndex(0) ->setCellValue('Z'.$i, $value['demo']) ->setCellValue('AA'.$i, $value['demo']); $i++; } $objPHPExcel->getActiveSheet()->setTitle('Simple'); $objPHPExcel->setActiveSheetIndex(0); /** 输出到指定目录 */ $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007'); $objWriter->save('simple.xlsx');//文件保存路径 /** 输出到浏览器直接下载打开 */ $file_name = 'batchTemplate.xlsx'; header('Content-Type:application/vnd.ms-excel'); //指定下载文件类型 header('Content-Disposition: attachment; filename="'.$file_name.'"'); //指定下载文件的描述 header('Content-Length:'.filesize($input_file)); //指定下载文件的大小 /** 将文件内容读取出来并直接输出,以便下载 */ readfile($input_file);
Related recommendations:
How to import PHPExcel files into Thinkphp3.2.3
The above is the detailed content of PHPExcel method to modify existing Excel. For more information, please follow other related articles on the PHP Chinese website!