我想将多个Excel工作表中的工作表合并到一个新的Excel文件中的1个工作表中。
我参考了讨论https://phpexcel.codeplex.com/discussions/390898
我不明白MarkBaker使用toArray()的意思。我的意思是我该如何使用它。 我目前的守则是:
$file1="file1.xlsx";
$objPHPExcel1 = PHPExcel_IOFactory::load($file1);
$file2="file2.xlsx";
$outputFile = "output.xlsx";
$objPHPExcel2 = PHPExcel_IOFactory::load($file2);
$sheet = $objPHPExcel2->getActiveSheet();
$objPHPExcel1->addExternalSheet($sheet);
$objWriter = new PHPExcel_Writer_Excel2007($objPHPExcel1);
$objWriter->save($outputFile);
有了这个,我可以将各种文件的不同工作表放到一个新的工作簿中,但作为不同的工作表。
如果像维特曼所说的那样,我该怎样做才能把它全部放到同一张纸上? first_excel_file_with_one_worksheet - 空行 - second_excel_file_with_one_worksheet - 空行 - 等
答案 0 :(得分:0)
//从办公地点更新
$filenames = array('doc1.xlsx', 'doc2.xlsx');
$bigExcel = new PHPExcel();
$bigExcel->removeSheetByIndex(0);
$reader = PHPExcel_IOFactory::createReader($input_file_type);
foreach ($filenames as $filename) {
$excel = $reader->load($filename);
foreach ($excel->getAllSheets() as $sheet) {
$bigExcel->addExternalSheet($sheet);
}
foreach ($excel->getNamedRanges() as $namedRange) {
$bigExcel->addNamedRange($namedRange);
}
}
$writer = PHPExcel_IOFactory::createWriter($bigExcel, 'Excel5');
$file_creation_date = date("Y-m-d");
// name of file, which needs to be attached during email sending
$saving_name = "Report_Name" . $file_creation_date . '.xls';
// save file at some random location
$writer->save($file_path_location . $saving_name);
// More Detail : with different object:
这里解释了将多个xls文件合并为单个文件: 我将描述一点不同: http://rosevinod.wordpress.com/2014/03/15/combine-two-or-more-xls-files-as-worksheets-phpexcel/