简体   繁体   中英

Phpspreadsheet clone won't work and timeout

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM