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

时间:2018-03-23 21:56:20

标签: php phpspreadsheet

我第一次使用PhpSpreadsheet并且一直都很棒。然而今天我需要制作一个文件,其中模板复制多张(超过300张)。 查看文档,它使用克隆方法。 但是,执行时,代码不会给出错误或异常。只是保持“等待本地主机”并突然停止。 我已经增加了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 );

我尝试使用for循环,即使没有它也会这样做。

这可能是PHP7的一些问题吗?

欢迎任何帮助。

1 个答案:

答案 0 :(得分:1)

我的解决方案&#34;现在:

在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));
            }
      }

它不是一个完美的解决方案,但它完成了工作,至少对我而言。