Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/249.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在多张图纸中添加一个模板phpspreadsheet_Php_Phpexcel_Phpspreadsheet - Fatal编程技术网

如何在多张图纸中添加一个模板phpspreadsheet

如何在多张图纸中添加一个模板phpspreadsheet,php,phpexcel,phpspreadsheet,Php,Phpexcel,Phpspreadsheet,我正在使用phpspreadsheet,我需要两张名为3rd&5th的表格,但每当我在第二张表格中加载excel表格时,整个电子表格都会被新的电子表格替换 我在网上找到了,但没有找到这样的问题,所以,我发布了这个问题 代码 $this->spreadsheet = new Spreadsheet(); $reader = IOFactory::createReader('Xlsx'); $this->spreadsheet = $reader->load('../images/

我正在使用
phpspreadsheet
,我需要两张名为
3rd
&
5th
的表格,但每当我在第二张表格中加载excel表格时,整个电子表格都会被新的电子表格替换

我在网上找到了,但没有找到这样的问题,所以,我发布了这个问题

代码

$this->spreadsheet = new Spreadsheet();
$reader = IOFactory::createReader('Xlsx');
$this->spreadsheet = $reader->load('../images/excel.xlsx');
$this->spreadsheet->setActiveSheetIndex(0)->setTitle('3rd');
$this->spreadsheet->createSheet()->setTitle('5th');
$this->spreadsheet->setActiveSheetIndex(1);
$reader = IOFactory::createReader('Xlsx');
$this->spreadsheet = $reader->load('../images/excel.xlsx');

如何在两个工作表中加载相同的excel模板?

不知道如何将一个模板加载到多个工作表中,但根据
phpspreadsheet
的文档,您可以在加载模板后克隆它

$this->spreadsheet = new Spreadsheet();
// COPY TEMPLATE INTO FIRST SHEET
$reader = IOFactory::createReader('Xlsx');
$this->spreadsheet = $reader->load('../images/excel.xlsx');
$this->spreadsheet->setActiveSheetIndex(0)->setTitle('3rd');
// CLONE FIRST SHEET
$clone = clone $this->spreadsheet->getSheetByName('3rd');
$clone->setTitle('5th');
$this->spreadsheet->addSheet($clone);

希望您喜欢我的备选答案。

不知道如何将一个模板加载到多个工作表,但根据
phpspreadsheet
的文档,您可以在加载模板后克隆它

$this->spreadsheet = new Spreadsheet();
// COPY TEMPLATE INTO FIRST SHEET
$reader = IOFactory::createReader('Xlsx');
$this->spreadsheet = $reader->load('../images/excel.xlsx');
$this->spreadsheet->setActiveSheetIndex(0)->setTitle('3rd');
// CLONE FIRST SHEET
$clone = clone $this->spreadsheet->getSheetByName('3rd');
$clone->setTitle('5th');
$this->spreadsheet->addSheet($clone);

希望你喜欢我的备选答案。

谢谢,我喜欢你的备选方式,节省了我的很多时间很高兴你喜欢它汉克斯,我喜欢你的备选方式,节省了我的很多时间很高兴你喜欢它