问答一下,轻松解决,电脑应用解决专家!
主板显卡CPU内存显示器
硬盘维修显卡维修显示器维修
注册表系统命令DOS命令Win8
存储光存储鼠标键盘
内存维修打印机维修
WinXPWin7Win10/Win11
硬件综合机箱电源散热器手机数码
主板维修CPU维修键盘鼠标维修
Word教程Excel教程PowerPointWPS
网络工具系统工具图像工具
数据库javascriptLinux系统
PHP教程CSS教程XML教程

phpExcel读excel模板并生成新excel文件

更新时间:2021-11-12 17:09 作者:佚名点击:

导出数据时,希望按模板显示,可用此法。

if (PHP_SAPI == 'cli')

	die('This example should only be run from a Web Browser');


/** Include PHPExcel */
require_once  '../PHPExcel-1.8/Classes/PHPExcel.php';
require_once '../class/db.class.php';
require_once '../PHPExcel-1.8/Classes/PHPExcel/IOFactory.php';//added


// Create new PHPExcel object
//$objPHPExcel = new PHPExcel();
$objReader = PHPExcel_IOFactory::createReader('Excel2007');
$objPHPExcel = $objReader->load ("FCR-SAMPLE.xlsx");
// Miscellaneous glyphs, UTF-8
//print_r($objPHPExcel);exit;


$objPHPExcel->setActiveSheetIndex(0)->setCellValue("A2",$_GET["receiveNumber"])->setCellValue("G3",$_GET['receiveNumber']);


// Set active sheet index to the first sheet, so Excel opens this as the first sheet
$objPHPExcel->setActiveSheetIndex(0);


// Redirect output to a client’s web browser (Excel2007)
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="cargoReceipt.xlsx"');
header('Cache-Control: max-age=0');
// If you're serving to IE 9, then the following may be needed
header('Cache-Control: max-age=1');


// If you're serving to IE over SSL, then the following may be needed
header ('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
header ('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); // always modified
header ('Cache-Control: cache, must-revalidate'); // HTTP/1.1
header ('Pragma: public'); // HTTP/1.0


$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->save('php://output');
exit;
顶一下
(0)
0%
踩一下
(0)
0%
------分隔线----------------------------
你可能感兴趣的内容