Wednesday, 15 May 2019

PhpSpreadsheet: Tables get lost in the process

I have an Excel file that I read and write to with PhpSpreadsheet. All my tables and references disappear in the process. Is there a flag I need to set to true/false or are tables just something that PhpSpreadsheet can't handle? See screenshots of before and after export.

I've tried different true/false combos of these without any luck setIncludeCharts(true); and setPreCalculateFormulas(true)

Anything obvious I'm missing here?

require 'vendor/autoload.php';

use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;

$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader('Xlsx');
$spreadsheet = $reader->load("template.xlsx");

header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="result.xlsx"');
header('Cache-Control: max-age=0');

$writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Xlsx');
$writer->save('php://output');
exit;

I suppress these notices/warnings with error_reporting(0) if it has anything to do with it. However that is in the PhpSpreadsheet code, which I'm not really supposed to mess with:

Notice: Undefined offset: 2 in /vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Calculation/Calculation.php on line 3472

Warning: trim() expects parameter 1 to be string, array given in /vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Calculation/Calculation.php on line 3680

I also tried a different version of the same template that gave me this error:

Fatal error: Uncaught PhpOffice\PhpSpreadsheet\Exception: Invalid cell coordinate 1))) in vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Cell/Coordinate.php:42 Stack trace: #0 vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Cell/Coordinate.php(111): PhpOffice\PhpSpreadsheet\Cell\Coordinate::coordinateFromString('1)))')

1 vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Cell/Coordinate.php(86):

PhpOffice\PhpSpreadsheet\Cell\Coordinate::absoluteCoordinate('1)))')

2 vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Writer/Xlsx/Workbook.php(416):

PhpOffice\PhpSpreadsheet\Cell\Coordinate::absoluteReference('1)))') #3 vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Writer/Xlsx/Workbook.php(267): PhpOffice\PhpSpreadsheet\Writer\Xlsx\Workbook->writeDefinedNameForPrintArea(Object(PhpOffice\PhpSpreadsheet\Shared\XMLWriter), Object(PhpOffice\PhpS in vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Cell/Coordinate.php on line 42

enter image description here enter image description here



from PhpSpreadsheet: Tables get lost in the process

No comments:

Post a Comment