From fdc8e8d17a64274629524ac751f142369d876db7 Mon Sep 17 00:00:00 2001 From: Alexander Gunkel Date: Sun, 31 Jan 2021 18:26:50 +0100 Subject: [PATCH] Fix/1674 (#1688) * Treat inline strings like strings in Open Document because it has no specific inline-string format * implement data-type error Co-authored-by: Mark Baker --- CHANGELOG.md | 1 + src/PhpSpreadsheet/Writer/Ods/Content.php | 11 +- .../Writer/Ods/ContentTest.php | 4 + tests/data/Writer/Ods/content-with-data.xml | 126 ++++++++++-------- 4 files changed, 78 insertions(+), 64 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 24ddedc4..0cab5853 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -34,6 +34,7 @@ and this project adheres to [Semantic Versioning](https://semver.org). - Fix For Null Exception on ODS Read of Page Settings. [#1772](https://github.com/PHPOffice/PhpSpreadsheet/issues/1772) - Fix Xlsx reader overriding manually set number format with builtin number format. [PR #1805](https://github.com/PHPOffice/PhpSpreadsheet/pull/1805) +- Fix for not yet implemented data-types in Open Documend writer [Issue #1674](https://github.com/PHPOffice/PhpSpreadsheet/issues/1674) ## 1.16.0 - 2020-12-31 diff --git a/src/PhpSpreadsheet/Writer/Ods/Content.php b/src/PhpSpreadsheet/Writer/Ods/Content.php index 96e66850..3222a9c7 100644 --- a/src/PhpSpreadsheet/Writer/Ods/Content.php +++ b/src/PhpSpreadsheet/Writer/Ods/Content.php @@ -196,7 +196,10 @@ class Content extends WriterPart break; case DataType::TYPE_ERROR: - throw new Exception('Writing of error not implemented yet.'); + $objWriter->writeAttribute('table:formula', 'of:=#NULL!'); + $objWriter->writeAttribute('office:value-type', 'string'); + $objWriter->writeAttribute('office:string-value', ''); + $objWriter->writeElement('text:p', '#NULL!'); break; case DataType::TYPE_FORMULA: @@ -217,10 +220,6 @@ class Content extends WriterPart $objWriter->writeAttribute('office:value', $formulaValue); $objWriter->writeElement('text:p', $formulaValue); - break; - case DataType::TYPE_INLINE: - throw new Exception('Writing of inline not implemented yet.'); - break; case DataType::TYPE_NUMERIC: $objWriter->writeAttribute('office:value-type', 'float'); @@ -228,6 +227,8 @@ class Content extends WriterPart $objWriter->writeElement('text:p', $cell->getValue()); break; + case DataType::TYPE_INLINE: + // break intentionally omitted case DataType::TYPE_STRING: $objWriter->writeAttribute('office:value-type', 'string'); $objWriter->writeElement('text:p', $cell->getValue()); diff --git a/tests/PhpSpreadsheetTests/Writer/Ods/ContentTest.php b/tests/PhpSpreadsheetTests/Writer/Ods/ContentTest.php index 4086914d..2ebd4984 100644 --- a/tests/PhpSpreadsheetTests/Writer/Ods/ContentTest.php +++ b/tests/PhpSpreadsheetTests/Writer/Ods/ContentTest.php @@ -59,6 +59,7 @@ class ContentTest extends TestCase $worksheet1->setCellValue('A2', true); // Boolean $worksheet1->setCellValue('B2', false); // Boolean + $worksheet1->setCellValueExplicit( 'C2', '=IF(A3, CONCATENATE(A1, " ", A2), CONCATENATE(A2, " ", A1))', @@ -70,6 +71,9 @@ class ContentTest extends TestCase ->getNumberFormat() ->setFormatCode(NumberFormat::FORMAT_DATE_DATETIME); + $worksheet1->setCellValueExplicit('F1', null, DataType::TYPE_ERROR); + $worksheet1->setCellValueExplicit('G1', 'Lorem ipsum', DataType::TYPE_INLINE); + // Styles $worksheet1->getStyle('A1')->getFont()->setBold(true); $worksheet1->getStyle('B1')->getFont()->setItalic(true); diff --git a/tests/data/Writer/Ods/content-with-data.xml b/tests/data/Writer/Ods/content-with-data.xml index a9048047..a13ed0be 100644 --- a/tests/data/Writer/Ods/content-with-data.xml +++ b/tests/data/Writer/Ods/content-with-data.xml @@ -1,105 +1,113 @@ - - - - + + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - + - - + + - + 1 - + 12345.6789 - + 1 - + 01234 - + Lorem ipsum - + + #NULL! + + + Lorem ipsum + + - + 1 - - + + - + 1 1 - + 42798.572060185 - - + + + + - - + + - + 2 - + - + - \ No newline at end of file +