diff --git a/src/PhpSpreadsheet/Reader/Ods.php b/src/PhpSpreadsheet/Reader/Ods.php
index ceb345dc3f..e3d86e624a 100644
--- a/src/PhpSpreadsheet/Reader/Ods.php
+++ b/src/PhpSpreadsheet/Reader/Ods.php
@@ -492,7 +492,7 @@ public function loadIntoExisting(string $filename, Spreadsheet $spreadsheet): Sp
break;
case 'boolean':
$type = DataType::TYPE_BOOL;
- $dataValue = ($allCellDataText == 'TRUE') ? true : false;
+ $dataValue = ($cellData->getAttributeNS($officeNs, 'boolean-value') === 'true') ? true : false;
break;
case 'percentage':
diff --git a/src/PhpSpreadsheet/Writer/Ods/Content.php b/src/PhpSpreadsheet/Writer/Ods/Content.php
index 7b052bbccb..7ffcd46b6d 100644
--- a/src/PhpSpreadsheet/Writer/Ods/Content.php
+++ b/src/PhpSpreadsheet/Writer/Ods/Content.php
@@ -2,6 +2,7 @@
namespace PhpOffice\PhpSpreadsheet\Writer\Ods;
+use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalculationException;
use PhpOffice\PhpSpreadsheet\Cell\Cell;
use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
@@ -209,8 +210,8 @@ private function writeCells(XMLWriter $objWriter, RowCellIterator $cells): void
switch ($cell->getDataType()) {
case DataType::TYPE_BOOL:
$objWriter->writeAttribute('office:value-type', 'boolean');
- $objWriter->writeAttribute('office:value', $cell->getValueString());
- $objWriter->writeElement('text:p', $cell->getValueString());
+ $objWriter->writeAttribute('office:boolean-value', $cell->getValue() ? 'true' : 'false');
+ $objWriter->writeElement('text:p', Calculation::getInstance()->getLocaleBoolean($cell->getValue() ? 'TRUE' : 'FALSE'));
break;
case DataType::TYPE_ERROR:
diff --git a/tests/PhpSpreadsheetTests/Calculation/CalculationFunctionListTest.php b/tests/PhpSpreadsheetTests/Calculation/CalculationFunctionListTest.php
index f961c7ac7a..978162667f 100644
--- a/tests/PhpSpreadsheetTests/Calculation/CalculationFunctionListTest.php
+++ b/tests/PhpSpreadsheetTests/Calculation/CalculationFunctionListTest.php
@@ -13,21 +13,15 @@ class CalculationFunctionListTest extends TestCase
{
private string $compatibilityMode;
- private string $locale;
-
protected function setUp(): void
{
$this->compatibilityMode = Functions::getCompatibilityMode();
- $calculation = Calculation::getInstance();
- $this->locale = $calculation->getLocale();
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
}
protected function tearDown(): void
{
Functions::setCompatibilityMode($this->compatibilityMode);
- $calculation = Calculation::getInstance();
- $calculation->setLocale($this->locale);
}
/**
diff --git a/tests/PhpSpreadsheetTests/Calculation/CalculationTest.php b/tests/PhpSpreadsheetTests/Calculation/CalculationTest.php
index 79685d2678..797b0bfd78 100644
--- a/tests/PhpSpreadsheetTests/Calculation/CalculationTest.php
+++ b/tests/PhpSpreadsheetTests/Calculation/CalculationTest.php
@@ -15,21 +15,15 @@ class CalculationTest extends TestCase
{
private string $compatibilityMode;
- private string $locale;
-
protected function setUp(): void
{
$this->compatibilityMode = Functions::getCompatibilityMode();
- $calculation = Calculation::getInstance();
- $this->locale = $calculation->getLocale();
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
}
protected function tearDown(): void
{
Functions::setCompatibilityMode($this->compatibilityMode);
- $calculation = Calculation::getInstance();
- $calculation->setLocale($this->locale);
}
/**
diff --git a/tests/PhpSpreadsheetTests/Reader/Ods/BooleanDataTest.php b/tests/PhpSpreadsheetTests/Reader/Ods/BooleanDataTest.php
new file mode 100644
index 0000000000..28efec1970
--- /dev/null
+++ b/tests/PhpSpreadsheetTests/Reader/Ods/BooleanDataTest.php
@@ -0,0 +1,83 @@
+locale = $calculation->getLocale();
+ }
+
+ protected function tearDown(): void
+ {
+ $calculation = Calculation::getInstance();
+ $calculation->setLocale($this->locale);
+ if ($this->tempfile !== '') {
+ unlink($this->tempfile);
+ $this->tempfile = '';
+ }
+ }
+
+ public function testBooleanData(): void
+ {
+ $spreadsheetOld = new Spreadsheet();
+ $sheetOld = $spreadsheetOld->getActiveSheet();
+ $sheetOld->getCell('A1')->setValue(true);
+ $sheetOld->getCell('A2')->setValue(false);
+ $writer = new OdsWriter($spreadsheetOld);
+ $this->tempfile = File::temporaryFileName();
+ $writer->save($this->tempfile);
+ $spreadsheetOld->disconnectWorksheets();
+ $reader = new OdsReader();
+ $spreadsheet = $reader->load($this->tempfile);
+ $sheet = $spreadsheet->getActiveSheet();
+ self::assertTrue($sheet->getCell('A1')->getValue());
+ self::assertFalse($sheet->getCell('A2')->getValue());
+ $spreadsheet->disconnectWorksheets();
+ $zipFile = 'zip://' . $this->tempfile . '#content.xml';
+ $contents = (string) file_get_contents($zipFile);
+ self::assertStringContainsString('TRUE', $contents);
+ self::assertStringContainsString('FALSE', $contents);
+ }
+
+ public function testBooleanDataGerman(): void
+ {
+ $calculation = Calculation::getInstance();
+ $calculation->setLocale('de');
+ $spreadsheetOld = new Spreadsheet();
+ $sheetOld = $spreadsheetOld->getActiveSheet();
+ $sheetOld->getCell('A1')->setValue(true);
+ $sheetOld->getCell('A2')->setValue(false);
+ $writer = new OdsWriter($spreadsheetOld);
+ $this->tempfile = File::temporaryFileName();
+ $writer->save($this->tempfile);
+ $spreadsheetOld->disconnectWorksheets();
+ $reader = new OdsReader();
+ $spreadsheet = $reader->load($this->tempfile);
+ $sheet = $spreadsheet->getActiveSheet();
+ self::assertTrue($sheet->getCell('A1')->getValue());
+ self::assertFalse($sheet->getCell('A2')->getValue());
+ $spreadsheet->disconnectWorksheets();
+ $zipFile = 'zip://' . $this->tempfile . '#content.xml';
+ $contents = (string) file_get_contents($zipFile);
+ self::assertStringContainsString('WAHR', $contents);
+ self::assertStringContainsString('FALSCH', $contents);
+ self::assertStringNotContainsString('TRUE', $contents);
+ self::assertStringNotContainsString('FALSE', $contents);
+ }
+}
diff --git a/tests/data/Writer/Ods/content-with-data.xml b/tests/data/Writer/Ods/content-with-data.xml
index 12140fa926..bb115583c9 100644
--- a/tests/data/Writer/Ods/content-with-data.xml
+++ b/tests/data/Writer/Ods/content-with-data.xml
@@ -95,11 +95,11 @@
-
- 1
+
+ TRUE
-
-
+
+ FALSE
1 1