From 1d86675e048862c34172d76db409e7ad10b73a84 Mon Sep 17 00:00:00 2001 From: oleibman <10341515+oleibman@users.noreply.github.com> Date: Wed, 3 Jul 2024 19:56:38 -0700 Subject: [PATCH 1/5] Ods Xml Reader and Whitespace Text Nodes Fix #804, opened in Dec. 2018, and closed as stale in Feb. 2019, and which I have re-opened to be closed properly by this PR. Better late than never, I suppose. A third party generated an ODS spreadsheet which PhpSpreadsheet could not read. By way of explanation, the xml in the file contained lots of whitespace between tags, which is wonderful for those humans among us who have to analyze it; but PhpSpreadsheet was not prepared for it. It is now. --- src/PhpSpreadsheet/Reader/Ods.php | 6 ++- .../Reader/Ods/Issue804Test.php | 38 ++++++++++++++++++ tests/data/Reader/Ods/issue.804.ods | Bin 0 -> 4979 bytes 3 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 tests/PhpSpreadsheetTests/Reader/Ods/Issue804Test.php create mode 100644 tests/data/Reader/Ods/issue.804.ods diff --git a/src/PhpSpreadsheet/Reader/Ods.php b/src/PhpSpreadsheet/Reader/Ods.php index ceb345dc3f..746210ab3f 100644 --- a/src/PhpSpreadsheet/Reader/Ods.php +++ b/src/PhpSpreadsheet/Reader/Ods.php @@ -6,6 +6,7 @@ use DOMDocument; use DOMElement; use DOMNode; +use DOMText; use PhpOffice\PhpSpreadsheet\Cell\Coordinate; use PhpOffice\PhpSpreadsheet\Cell\DataType; use PhpOffice\PhpSpreadsheet\Helper\Dimension as HelperDimension; @@ -403,8 +404,11 @@ public function loadIntoExisting(string $filename, Spreadsheet $spreadsheet): Sp } $columnID = 'A'; - /** @var DOMElement $cellData */ + /** @var DOMElement|DOMText $cellData */ foreach ($childNode->childNodes as $cellData) { + if ($cellData instanceof DOMText) { + continue; // should just be whitespace + } if ($this->getReadFilter() !== null) { if (!$this->getReadFilter()->readCell($columnID, $rowID, $worksheetName)) { if ($cellData->hasAttributeNS($tableNs, 'number-columns-repeated')) { diff --git a/tests/PhpSpreadsheetTests/Reader/Ods/Issue804Test.php b/tests/PhpSpreadsheetTests/Reader/Ods/Issue804Test.php new file mode 100644 index 0000000000..afb33dabe8 --- /dev/null +++ b/tests/PhpSpreadsheetTests/Reader/Ods/Issue804Test.php @@ -0,0 +1,38 @@ + + + Name', $data); + } + } + + public function testIssue2810(): void + { + // Whitespace between Xml nodes + $filename = 'tests/data/Reader/Ods/issue.804.ods'; + $reader = new Ods(); + $spreadsheet = $reader->load($filename); + $sheet = $spreadsheet->getActiveSheet(); + self::assertSame('Straße', $sheet->getCell('G1')->getValue()); + $spreadsheet->disconnectWorksheets(); + } +} diff --git a/tests/data/Reader/Ods/issue.804.ods b/tests/data/Reader/Ods/issue.804.ods new file mode 100644 index 0000000000000000000000000000000000000000..b42de4cf635d248d117abde3ef3f084c93e3b9d6 GIT binary patch literal 4979 zcmb7|2{@Ep8^_1KWs8t#CTl3Wvb@QJu|&pJgc#E#8Z*X>U6!$A4_UKiEZH-*M9TVx zB0@+ZLfMHB@r}OEt9PS&tLrQ+Tvl>^$r$zfaihip9i=^W8EjtDIF|IdiU z!EjFhL$}{n;?QX1ui0pS9tX%q54`{x05DAj030FB^Pl5j4@24BKwxp=uJ*|C7%-{< z#G<~U5YRMO*_L+!Qxeq8Rz{OBLiF<|lTu|LdM0nc_PC9ZTOR>#@BpU6N|nMZ6s-kD zEyPmC?&WmY4jnyPHu7Vp+>5n(#!dz=bMA2dBlXzV3RN+Mnw=ud*EJQmqS$YZQB<{0 z$r9kpHI{AJGkH~b4>++s9FtchJ$DYQdFmzA_gRSC-kb*6}0zTqQpJE!{{^MJpO$mZGoC(_5BT z!Y=4zj7)eyM$ekiU-!{lmvQ<{bj%w@?)lC#UQX~T;P1YbY{cb>mo9^zh3WP{_uLsv z={h4=W~&)2A@42(HI3Kv&O6YsvZ-DwFApB~L->`+)qd=(%TmN)dom z2suS6fjH^?vlO42`@>yRgwu`j?+(G5Mp;u zRbf`qu7f0=D5HJBnagFKP??;#^;JkhEc;vg@v6sx&_#g|g|3_&={`*_g|vEpiA7LG z)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ViZ*+7 id!LYZb(AEAgzr8tLoZU1i~s-@(u Date: Thu, 4 Jul 2024 20:06:17 -0700 Subject: [PATCH 2/5] Documentation Updates Mostly in response to issue #3961, which noted some discrepancies, both positive and negative, between documentation and reality concerning ODS support. --- docs/index.md | 3 ++ docs/references/features-cross-reference.md | 35 +++++++++++---------- 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/docs/index.md b/docs/index.md index 9505181b79..d577d8982a 100644 --- a/docs/index.md +++ b/docs/index.md @@ -20,6 +20,9 @@ allow you to read and write various spreadsheet file formats such as Excel and L |CSV | ✓ | ✓ | |PDF (using either the TCPDF, Dompdf or mPDF libraries, which need to be installed separately)| | ✓ | +Note - reading or writing certain aspects of a spreadsheet may not be supported in all formats. For more details, please consult +[Features Cross-reference](./references/features-cross-reference.md). + # Getting started ## Software requirements diff --git a/docs/references/features-cross-reference.md b/docs/references/features-cross-reference.md index 37668ba82d..f116be511c 100644 --- a/docs/references/features-cross-reference.md +++ b/docs/references/features-cross-reference.md @@ -28,7 +28,7 @@ ✔ ✔ ● - ● + ● 6 ✔ N/A N/A @@ -389,7 +389,7 @@ Conditional Formatting - ● + ✔ ✔ ✖ ✖ @@ -414,7 +414,7 @@ ✔ ✔ ✔ - ✖ + ✔ ✔ N/A N/A @@ -502,7 +502,7 @@ ✔ ✔ ✔ - ✔ + ● ✔ N/A ✔ @@ -797,13 +797,13 @@ Alignment ✖ 3 - ✖ + ✔ ✖ ✖ ✖ N/A ✖ - ✖ + ✔ Background Image @@ -929,7 +929,7 @@ Macros ✖ - ✔ + ● 5 ✖ ✖ ✖ @@ -940,7 +940,7 @@ Form Controls ✖ - ✖ + ● 4 ✖ ✖ ✖ @@ -1001,6 +1001,9 @@ 1. Only text contents 2. Only BIFF8 files support Rich Text. Prior to that, comments could only be plain text 3. Only BIFF8 files support alignment and rotation. Prior to that, comments could only be unformatted text +4. Xlsx forms and controls can be read and written but not otherwise manipulated +5. Xlsx macros can be read and written; their values can be retrieved and changed, but only in a binary form which is unlikely to be useful +6. There is very limited support for reading styles from an Ods spreadsheet. Writing styles has better support, although Number Format is incomplete. ## Writers @@ -1184,7 +1187,7 @@ Row Height/Column Width ✔ ✔ - ✖ + ✔ N/A ✔ ✔ @@ -1256,7 +1259,7 @@ Number Format Mask ✔ ✔ - ✔ + ● N/A ✔ ✔ @@ -1472,10 +1475,10 @@ Merged Cells ✔ ✔ - ✖ + ✔ N/A ✔ - ✖ + ✔ Cell Comments @@ -1606,7 +1609,7 @@ Macros ✖ - ✔ + ● 5 ✖ N/A ✖ @@ -1615,7 +1618,7 @@ Form Controls ✖ - ✖ + ● 4 ✖ N/A ✖ @@ -1803,8 +1806,8 @@ Macros - $spreadsheet->getMacrosCode(); - $spreadsheet->setMacrosCode(); + $spreadsheet->getMacrosCode();5 + $spreadsheet->setMacrosCode();5 Security From 2897c4de33d7107b2038cd572f27ac96a2a29b9e Mon Sep 17 00:00:00 2001 From: oleibman <10341515+oleibman@users.noreply.github.com> Date: Thu, 4 Jul 2024 20:18:25 -0700 Subject: [PATCH 3/5] Missed One Doc Change --- docs/references/features-cross-reference.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/references/features-cross-reference.md b/docs/references/features-cross-reference.md index f116be511c..23dfbb3333 100644 --- a/docs/references/features-cross-reference.md +++ b/docs/references/features-cross-reference.md @@ -1501,10 +1501,10 @@ Alignment ✖ - ✖ + ✔ ✖ N/A - ✖ + ✔ N/A From f6823c79e825518afbc6aa883ff5e22630865444 Mon Sep 17 00:00:00 2001 From: oleibman <10341515+oleibman@users.noreply.github.com> Date: Sat, 6 Jul 2024 20:26:15 -0700 Subject: [PATCH 4/5] More Doc Updates --- docs/references/features-cross-reference.md | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/docs/references/features-cross-reference.md b/docs/references/features-cross-reference.md index 23dfbb3333..746357894e 100644 --- a/docs/references/features-cross-reference.md +++ b/docs/references/features-cross-reference.md @@ -495,7 +495,7 @@ ✔ N/A ● - ● + ● 7 Number Format Mask @@ -517,7 +517,7 @@ ✔ N/A ✖ - ● + ● 7 Horizontal @@ -583,7 +583,7 @@ ✔ N/A ✔ - ✔ + ● 7 Patterned @@ -605,7 +605,7 @@ ✔ N/A ✔ - ✔ + ● 7 Font Face @@ -704,7 +704,7 @@ ✔ N/A ● - ✔ + ● 7 Line Style @@ -1004,6 +1004,7 @@ 4. Xlsx forms and controls can be read and written but not otherwise manipulated 5. Xlsx macros can be read and written; their values can be retrieved and changed, but only in a binary form which is unlikely to be useful 6. There is very limited support for reading styles from an Ods spreadsheet. Writing styles has better support, although Number Format is incomplete. +7. In most cases, Html reader processes only inline styles; styles provided by Css classes may be ignored. ## Writers From f6f155263c7cfb0feafcb71d1a7af3526548703d Mon Sep 17 00:00:00 2001 From: oleibman <10341515+oleibman@users.noreply.github.com> Date: Wed, 10 Jul 2024 20:13:50 -0700 Subject: [PATCH 5/5] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 12b5959339..760df33ee4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -38,6 +38,7 @@ and this project adheres to [Semantic Versioning](https://semver.org). - Problem rendering line chart with missing plot label. [PR #4074](https://github.com/PHPOffice/PhpSpreadsheet/pull/4074) - More RTL in Xlsx/Html Comments [Issue #4004](https://github.com/PHPOffice/PhpSpreadsheet/issues/4004) [PR #4065](https://github.com/PHPOffice/PhpSpreadsheet/pull/4065) - Empty String in sharedStrings. [Issue #4063](https://github.com/PHPOffice/PhpSpreadsheet/issues/4063) [PR #4064](https://github.com/PHPOffice/PhpSpreadsheet/pull/4064) +- Ods Xml Reader and Whitespace Text Nodes. [Issue #804](https://github.com/PHPOffice/PhpSpreadsheet/issues/804) [PR #4087](https://github.com/PHPOffice/PhpSpreadsheet/pull/4087) ## 2024-05-11 - 2.1.0