I am trying to write a string that contains double quotes in a cell, write it to disk and read it again from an xls
file.
Example strings are:
single quote "
double quotes ""
I set the cell values via
// $page is of type PhpOffice\PhpSpreadsheet\Worksheet\Worksheet
$page->setCellValueExplicitByColumnAndRow($columnIndex, $rowIndex, $sanitizedValue, DataType::TYPE_STRING);
$page->getCellByColumnAndRow($columnIndex, $rowIndex)->getStyle()->setQuotePrefix(true);
Reading the value back at this stage (without writing to disk) works as expected via either getCalculatedValue()
, getFormattedValue()
or getValue()
.
However as soon as the file is written and read again via a Xls
writer I get a String offset cast exception
in PhpSpreadsheet\Reader\Xls.php:7863
Partial stack trace:
Stack trace:
#0 C:\temp\test\vendor\phpoffice\phpspreadsheet\src\PhpSpreadsheet\Reader\Xls.php(7863): Illuminate\Foundation\Bootstrap\HandleExceptions->handleError(8, 'String offset c...', 'C:\\temp\\files...', 7863, Array)
#1 C:\temp\test\vendor\phpoffice\phpspreadsheet\src\PhpSpreadsheet\Reader\Xls.php(3060): PhpOffice\PhpSpreadsheet\Reader\Xls::getUInt2d('\xAC\x01\x00\x00\xFF\x00\x00\x00\x17\x00\x01u\x00m\x00...', 16487)
#2 C:\temp\test\vendor\phpoffice\phpspreadsheet\src\PhpSpreadsheet\Reader\Xls.php(737): PhpOffice\PhpSpreadsheet\Reader\Xls->readSst()
I have tried
- using
DataType::TYPE_STRING2
- with and without
setQuotePrefix
- escaping the string as formula
single quote "
=>'= single quote "
- searched if strings need to be escaped with phpSpreadsheet (not as far as I could find)
- writing the sample texts directly via excel and importing that file (this works flawlessly)
but at this point I am out of Ides and would appreciate any hints.
phpoffice/phpspreadsheet: 1.18.0
php-version: 7.3.6
Excel Format: xls