Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ods writer and reader handle bool values differently (with diff of potential fix) #460

Closed
discordier opened this issue Apr 10, 2018 · 3 comments · Fixed by #4093
Closed

Comments

@discordier
Copy link

discordier commented Apr 10, 2018

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.

@stale
Copy link

stale bot commented Jun 9, 2018

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
If this is still an issue for you, please try to help by debugging it further and sharing your results.
Thank you for your contributions.

@stale stale bot added the stale label Jun 9, 2018
@stale stale bot closed this as completed Jun 16, 2018
@discordier
Copy link
Author

Well, the issue is still unresolved and present, so I wonder if it is wise to close it despite no-one has responded yet.

@oleibman
Copy link
Collaborator

Reopening, expect a fix in a day or two.

@oleibman oleibman reopened this Jul 11, 2024
@stale stale bot removed the stale label Jul 11, 2024
oleibman added a commit to oleibman/PhpSpreadsheet that referenced this issue Jul 12, 2024
Fix PHPOffice#460. Another in the "better late than never" series, closed as stale in June 2018. Ods Writer and Ods Reader handle booleans differently; what is worse, neither of them do it correctly. They will now match the behavior of LibreOffice. Reporter said that part of the xml would vary depending on locale; I believe that part is never actually used, but I do emulate that behavior.
@oleibman oleibman mentioned this issue Jul 12, 2024
11 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

2 participants