You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There should be no exception thrown on $activeSheet->setCellValueByColumnAndRow(1, 1, null); when used with PhpOffice\PhpSpreadsheet\Shared\Font::setAutoSizeMethod(PhpOffice\PhpSpreadsheet\Shared\Font::AUTOSIZE_METHOD_EXACT); and $activeSheet->getColumnDimension(...)->setAutoSize(true);
Replacing null value by "" will solve the problem, but I have too many old programs using null values and it would be painful to modify them all to wokaround this issue.
So I think (for backward compatibility) that PhpSpreadsheet should add the missing $value ?? "" check here in its code.
Thank you!
What is the current behavior?
An exception is thrown (the output comes from version 1.18.0):
Argument 1 passed to PhpOffice\PhpSpreadsheet\Shared\Font::getTextWidthPixelsExact() must be of the type string, null given, called in src\PhpSpreadsheet\Shared\Font.php on line 254
at src\PhpSpreadsheet\Shared\Font.php(277)
#0 src\PhpSpreadsheet\Shared\Font.php(254): PhpOffice\PhpSpreadsheet\Shared\Font::getTextWidthPixelsExact(NULL, Object(PhpOffice\PhpSpreadsheet\Style\Font), 0)
#1 src\PhpSpreadsheet\Worksheet\Worksheet.php(766): PhpOffice\PhpSpreadsheet\Shared\Font::calculateColumnWidth(Object(PhpOffice\PhpSpreadsheet\Style\Font), NULL, 0, Object(PhpOffice\PhpSpreadsheet\Style\Font))
#2 src\PhpSpreadsheet\Writer\Xlsx\Worksheet.php(369): PhpOffice\PhpSpreadsheet\Worksheet\Worksheet->calculateColumnWidths()
#3 src\PhpSpreadsheet\Writer\Xlsx\Worksheet.php(67): PhpOffice\PhpSpreadsheet\Writer\Xlsx\Worksheet->writeCols(Object(PhpOffice\PhpSpreadsheet\Shared\XMLWriter), Object(PhpOffice\PhpSpreadsheet\Worksheet\Worksheet))
#4 src\PhpSpreadsheet\Writer\Xlsx.php(377): PhpOffice\PhpSpreadsheet\Writer\Xlsx\Worksheet->writeWorksheet(Object(PhpOffice\PhpSpreadsheet\Worksheet\Worksheet), Array, false)
What are the steps to reproduce?
Here is a minimal PHP script to reproduce the problem:
<?phprequire__DIR__ . '/vendor/autoload.php';
// Create new Spreadsheet object$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet();
PhpOffice\PhpSpreadsheet\Shared\Font::setTrueTypeFontPath('/path/to/some/fonts/');
PhpOffice\PhpSpreadsheet\Shared\Font::setAutoSizeMethod(PhpOffice\PhpSpreadsheet\Shared\Font::AUTOSIZE_METHOD_EXACT);
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet();
$activeSheet = $spreadsheet->createSheet();
$activeSheet->setTitle('Feuil1');
$spreadsheet->setActiveSheetIndexByName('Feuil1');
// Replacing null by '' will solve the problem:$activeSheet->setCellValueByColumnAndRow(1, 1, null);
$activeSheet->getColumnDimension(\PhpOffice\PhpSpreadsheet\Cell\Coordinate::stringFromColumnIndex(1))->setAutoSize(true);
$objWriter = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Xlsx');
$objWriter->save('C:\\temp\\output.xlsx');
?>
Which versions of PhpSpreadsheet and PHP are affected?
version 1.18.0 and master branch
The text was updated successfully, but these errors were encountered:
Hi,
this is a bug report.
What is the expected behavior?
There should be no exception thrown on
$activeSheet->setCellValueByColumnAndRow(1, 1, null);
when used withPhpOffice\PhpSpreadsheet\Shared\Font::setAutoSizeMethod(PhpOffice\PhpSpreadsheet\Shared\Font::AUTOSIZE_METHOD_EXACT);
and$activeSheet->getColumnDimension(...)->setAutoSize(true);
Replacing null value by "" will solve the problem, but I have too many old programs using null values and it would be painful to modify them all to wokaround this issue.
So I think (for backward compatibility) that PhpSpreadsheet should add the missing
$value ?? ""
check here in its code.Thank you!
What is the current behavior?
An exception is thrown (the output comes from version 1.18.0):
What are the steps to reproduce?
Here is a minimal PHP script to reproduce the problem:
Which versions of PhpSpreadsheet and PHP are affected?
version 1.18.0 and master branch
The text was updated successfully, but these errors were encountered: