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(); // 取得總行數
/** 循環(huán)讀取每個單元格的數據 */
$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);