PhpSpreadsheet
PhpSpreadsheet copied to clipboard
Exception 'PhpOffice\PhpSpreadsheet\Exception' with message 'Sheet does not exist.'
$excel = IOFactory::load("abc.xlsx"); $sheet1 = clone $excel->getSheet(0); $sheet1->setCellValue('A1','1111111111111'); $excel->addSheet($sheet1);
You need perform your addSheet before setCellValue. (You also need to change the sheet title first; I assume you just omitted that from your code fragment since you would have seen a different error if you didn't do that.)
This is a fairly unusual situation - it will happen only with cloned worksheets. It might be possible to make the PhpSpreadsheet code more resilient; that would add overhead to all setCellValue calls, and lose some functionality (setting quotePrefix attribute correctly) when it is needed. I'll have to think about whether it's worthwhile. In the meantime, you can re-code as above.