J
J
Jacky_James2016-03-13 17:41:09
PHP
Jacky_James, 2016-03-13 17:41:09

How to merge two files into one phpExcel (one sheet)?

There are two documents, how to connect the contents of one sheet of the first document and the contents of the sheet of the second document, in a new one?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrzej Wielski, 2016-03-13
@Jacky_James

stackoverflow.com/questions/31463423/phpexcel-comb...

$objPHPExcel1 = PHPExcel_IOFactory::load("MergeBook1.xlsx");
$objPHPExcel2 = PHPExcel_IOFactory::load("MergeBook2.xlsx");

foreach($objPHPExcel2->getSheetNames() as $sheetName) {
    $sheet = $objPHPExcel2->getSheetByName($sheetName);
    $sheet->setTitle($sheet->getTitle() . ' copied');
    $objPHPExcel1->addExternalSheet($sheet);
}

$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel1, 'Excel2007');
$objWriter->save('mergedBooks.xlsx');

Learn to google.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question