5

I am using PhpSpreahSheet to read multiple Excel file and merge them in one file. I read my files with this code :

$readerData = new \PhpOffice\PhpSpreadsheet\Reader\Xlsx();
$spreadData = $readerData->load("File/file1.xlsx");

$readerData = new \PhpOffice\PhpSpreadsheet\Reader\Xlsx();
$spreadData = $readerData->load("File/file2.xlsx");

Then, I use array_merge from php :

$mergeFileData = array_merge($sheetConfig, $sheetData);

And then I am writing my array into a new file :

$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
$sheet->fromArray($mergeFileDataEnd);
$writer = new Xlsx($spreadsheet);
$writer->save('mergedFile.xlsx');

The problem is, when I execute this code, the merge file is very slow to be generated, about the excel file, each one has more than 20k lines and 30 columns To generate the excel I had to increase the memory of the server and the time of execution limited at 30sec...

Do you any idea to optimize the time of execution ?

Edit : In fact, it's taking 10 minutes to generate my excel files...

Toto D
  • 109
  • 2
  • 12
  • 2
    I will try, I can't for the moment, I keep you in touch but I don't know if the pre-calculation will change something! Thanks for the answer ! – Toto D Oct 04 '18 at 07:36
  • 1
    Sorry for the delay, but it's changing nothing :/ – Toto D Oct 05 '18 at 06:58
  • 1
    It was much easier if you were able to provide those files. @jeuneapprenti solution worked like a charm. In my case reducing the execution time from 15 minutes to 8 seconds. In my case all of my creepy MS Excel formulas are existing in a hidden sheet. Are you sure your input files are not carrying empty sheets? – hpaknia Mar 09 '19 at 03:16
  • @hpaknia It took me some times to realize that this options was set on by default... Perhaps the default value should be true for this options... I'm sorry TotoD, i have no more solutions on this... – JeuneApprenti Mar 11 '19 at 15:41

0 Answers0