-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Closed
Description
This is:
- [X] a bug report
- [X] **not** a usage question (ask them on https://stackoverflow.com/questions/tagged/phpspreadsheet or https://gitter.im/PHPOffice/PhpSpreadsheet)
What is the expected behavior?
Ods reader should read boolean values properly.
What is the current behavior?
Ods reader can not read a boolean value created via Ods Writer.
What are the steps to reproduce?
<?php
require __DIR__ . '/vendor/autoload.php';
// Create new Spreadsheet object
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet();
// add code that show the issue here...
$sheet = $spreadsheet->getActiveSheet();
// Set the boolean value to true.
$sheet->getCellByColumnAndRow(1, 1)->setValue(true);
$writer = new \PhpOffice\PhpSpreadsheet\Writer\Ods($spreadsheet);
$writer->save('test.ods');
$reader = new \PhpOffice\PhpSpreadsheet\Reader\Ods();
$spreadsheet2 = $reader->load('test.ods')
$sheet2 = $spreadsheet2->getActiveSheet();
// This now returns false instead of true.
$sheet2->getCellByColumnAndRow(1, 1)->getValue();Can be fixed with src/PhpSpreadsheet/Reader/Ods.php (at line 529):
case 'boolean':
$type = DataType::TYPE_BOOL;
- $dataValue = ($allCellDataText == 'TRUE') ? true : false;
+ $dataValue = (bool) $cellData->getAttributeNS($officeNs, 'value');Which versions of PhpSpreadsheet and PHP are affected?
Probably all?
Elaboration on the generated and expected XML contents in the Ods file.
The PhpSpreadsheet Ods reader for a boolean cell expects (formatted for better readability):
<table:table-cell
office:value-type="boolean"
office:boolean-value="true"
calcext:value-type="boolean">
<text:p>TRUE</text:p>
</table:table-cell>The generated content by PhpSpreadsheet Ods writer for a boolean cell is (formatted for better readability):
<table:table-cell
table:style-name="ce1"
office:value-type="boolean"
office:value="1">
<text:p>1</text:p>
</table:table-cell>The generated content by LibreOffice 6.0.2.1.0+ with non english locale (German in this case) for a boolean cell is (formatted for better readability):
<table:table-cell
office:value-type="boolean"
office:boolean-value="true"
calcext:value-type="boolean">
<text:p>WAHR</text:p>
</table:table-cell>Hence the hard coded value of TRUE is not good at all.
Metadata
Metadata
Assignees
Labels
No labels