0

I have been using PhpSpreadsheet for the first time and always worked great. However today I needed to make one file where the template copies over several sheets (over 300 sheets). Looked the documentation and it uses the clone method. However, when executed, the code won't give and error or exception. Just keeps "waiting for localhost" and suddenly stops. I have increased the set_time_limit and even the memory limit, but still it refueses to work.

CODE

$File= IOFactory::createReader("Xlsx");
$Excel = $File->load('original.xlsx');
$clonedSheet = clone $Excel->getActiveSheet();
for($i = 0; $i <= 10; $i++)
{
$clonedSheet->setTitle('Simple Clone'.$i);
$Excel->addSheet($clonedSheet);
}

$writer = IOFactory::createWriter($Excel, "Xlsx");
$filename = "omitidos.xlsx";
$writer->save("output/".$filename );

I try'd taking the for loop and even without it it does the same.

Could it be some issue with PHP7?

Any help will be welcome.

ofesad
  • 33
  • 4
  • It's far more likely to be a timeout or a memory limit issue; cloning 300 worksheets is a pretty demanding task – Mark Baker Mar 23 '18 at 22:06
  • @MarkBaker i don't think so. As I mentioned on the example above, the issue still occurs even with 10 or 1 cloned sheet. The "clone" method seems to be the issue, for some reason. – ofesad Mar 24 '18 at 00:24

1 Answers1

1

My "solution" for now:

on PHPSpreadSheet\Worksheet\Worksheet.php file Go to the __clone function replace it with this one:

public function __clone()
    {
        foreach ($this as $key => $val) {
            if (is_object($val) || (is_array($val))) {
                $this->{$key} = unserialize(serialize($val));
            }
      }

it's not a perfect solution, but it gets the job done, at least for me.

ofesad
  • 33
  • 4