我一直在寻找如何使用两个现有文件执行此操作,看起来所有文档都在创建新文件.我想取一个文件,然后将第二个文件作为新工作表添加到它,然后将其保存到服务器.我一直试着这样无济于事:
$file="test.xls"; $file2="test2.xls"; $outputFile = "final.xls"; $phpExcel = new PHPExcel($file); $phpExcel->getActiveSheet(); $phpExcel->setActiveSheetIndex(0); $phpExcel->addSheet($file2); header("Content-Type: application/vnd.ms-excel"); header("Content-Disposition: attachment; filename=$outputFile"); header("Cache-Control: max-age=0"); $objWriter = PHPExcel_IOFactory::createWriter($phpExcel, "Excel5"); file_put_contents($outputFile, $objWriter);
任何帮助将不胜感激.PHP的新手.
这些天没有人读过文档吗?该文件夹中有一个完整的文档,名为"将文件/Documentation
读取到PHPExcel对象(它被称为PHPExcel User Documentation - Reading Spreadsheet Files
)",以及几十个示例(该/Documentation/Examples/Reader
文件夹是一个很好看的地方),而且没有一个使用new 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');