简体   繁体   English

Phpspreadsheet克隆将无法正常工作并超时

[英]Phpspreadsheet clone won't work and timeout

I have been using PhpSpreadsheet for the first time and always worked great. 我是第一次使用PhpSpreadsheet,并且始终运行良好。 However today I needed to make one file where the template copies over several sheets (over 300 sheets). 但是,今天我需要制作一个文件,模板在其中复制几张纸(超过300张纸)。 Looked the documentation and it uses the clone method. 查看了文档,它使用了clone方法。 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. 我增加了set_time_limit甚至是内存限制,但是仍然可以正常工作。

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. 我尝试使用for循环,即使没有循环也是如此。

Could it be some issue with PHP7? 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: 在PHPSpreadSheet \\ Worksheet \\ Worksheet.php文件上。转到__clone函数,用以下命令替换它:

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. 这不是一个完美的解决方案,但至少可以完成我的工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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