43_Merge_workbooks.php 829 B

1234567891011121314151617181920212223242526
  1. <?php
  2. use PhpOffice\PhpSpreadsheet\IOFactory;
  3. require __DIR__ . '/../Header.php';
  4. $helper->log('Load MergeBook1 from Xlsx file');
  5. $filename1 = __DIR__ . '/../templates/43mergeBook1.xlsx';
  6. $callStartTime = microtime(true);
  7. $spreadsheet1 = IOFactory::load($filename1);
  8. $helper->logRead('Xlsx', $filename1, $callStartTime);
  9. $helper->log('Load MergeBook2 from Xlsx file');
  10. $filename2 = __DIR__ . '/../templates/43mergeBook2.xlsx';
  11. $callStartTime = microtime(true);
  12. $spreadsheet2 = IOFactory::load($filename2);
  13. $helper->logRead('Xlsx', $filename2, $callStartTime);
  14. foreach ($spreadsheet2->getSheetNames() as $sheetName) {
  15. $sheet = $spreadsheet2->getSheetByName($sheetName);
  16. $sheet->setTitle($sheet->getTitle() . ' copied');
  17. $spreadsheet1->addExternalSheet($sheet);
  18. }
  19. // Save
  20. $helper->write($spreadsheet1, __FILE__);