简体   繁体   中英

PHPExcel copy sheet and change

$inputFileType = PHPExcel_IOFactory::identify($path . '/' . $fileName); 
$objReader = PHPExcel_IOFactory::createReader($inputFileType);
$objPHPExcel = $objReader->load($path . '/' . $fileName);

//temp sheet copy 2 times
for ($pageIndex=1; $pageIndex <= 2; $pageIndex++) {
   $tempSheet = $objPHPExcel->getSheet(0)->copy();
   $tempSheet->setTitle('Page ' . $pageIndex);

   $objPHPExcel->addSheet($tempSheet);
   unset($tempSheet);
}

$sheet = $objPHPExcel->getSheet(1);
$sheet->setCellValueExplicitByColumnAndRow(0, 1, 'TEST', PHPExcel_Cell_DataType::TYPE_STRING);

I copy a single excel sheet 2 times and I only make changes on page 2. This change applies to all pages

It seems you have no problem with your code. That code block works even if you use copy instead of clone. At least, I have run on my computer and it just changed content of the first row of page 2.

我通过将PHPExcel库版本1.7.6更新到1.8解决了该问题

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