这些天没有人阅读过文档吗?名为/ Documentation的文件夹中有一个关于将文件读取到PHPExcel对象的文件(它叫做PHPExcel用户文档 – 读取电子表格文件),还有几十个例子(/ Documentation / Examples / Reader文件夹是个好看的地方),并且他们都没有使用新的PHPExcel($file).任何示例或任何文档都没有说保存时使用file_put_contents().
$file1="test.xls";
$file2="test2.xls";
$outputFile = "final.xls";
// Files are loaded to PHPExcel using the IOFactory load() method
$objPHPExcel1 = PHPExcel_IOFactory::load($file1);
$objPHPExcel2 = PHPExcel_IOFactory::load($file2);
// Copy worksheets from $objPHPExcel2 to $objPHPExcel1
foreach($objPHPExcel2->getAllSheets() as $sheet) {
$objPHPExcel1->addExternalSheet($sheet)
}
// Save $objPHPExcel1 to browser as an .xls file
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel1, "Excel5");
header("Content-Type: application/vnd.ms-excel");
header("Content-Disposition: attachment; filename=$outputFile");
header("Cache-Control: max-age=0");
$objWriter->save('php://output');