From e2ec705ee8c5bd7d7daeee3d66b8425266287bfc Mon Sep 17 00:00:00 2001
From: oleibman <10341515+oleibman@users.noreply.github.com>
Date: Sat, 7 Dec 2024 00:26:40 -0800
Subject: [PATCH 1/2] Ods Writer Master Page Name
PR #2850 and PR #2851 added support for Worksheet Visibility to ODS. They work well when LibreOffice is used to open the spreadsheet. However, when Excel tries to open it, it reports corruption. Strictly speaking, this is not a PhpSpreadsheet problem, but, if we can fix it, we should.
It took a while to figure out what's bothering Excel. I'm not sure that all of what follows is necessary, but it works. It appears that it wants the content.xml `style:automatic-styles` definition for the `table` (i.e. worksheet) to include a `style:master-page-name` attribute. That attribute requires a corresponding definition in the `office:master-styles` section in styles.xml, and that attribute likewise requires a definition in `office:automatic-styles`.
The new entries in styles.xml can be used to specify things like header and footer. However, the ways that these are specified is distinctly different from what Excel (and therefore PhpSpreadsheet) does. Implementing that will be a good future project. However, for now, they will remain unsupported for Ods.
---
src/PhpSpreadsheet/Writer/Ods/Cell/Style.php | 1 +
src/PhpSpreadsheet/Writer/Ods/Styles.php | 13 ++++-
tests/data/Writer/Ods/content-arrays.xml | 49 ++++++++++++++++++-
tests/data/Writer/Ods/content-empty.xml | 2 +-
.../Writer/Ods/content-hidden-worksheet.xml | 4 +-
tests/data/Writer/Ods/content-with-data.xml | 4 +-
6 files changed, 65 insertions(+), 8 deletions(-)
diff --git a/src/PhpSpreadsheet/Writer/Ods/Cell/Style.php b/src/PhpSpreadsheet/Writer/Ods/Cell/Style.php
index 7573230689..c1c9f32c11 100644
--- a/src/PhpSpreadsheet/Writer/Ods/Cell/Style.php
+++ b/src/PhpSpreadsheet/Writer/Ods/Cell/Style.php
@@ -289,6 +289,7 @@ public function writeTableStyle(Worksheet $worksheet, int $sheetId): void
'style:name',
sprintf('%s%d', self::TABLE_STYLE_PREFIX, $sheetId)
);
+ $this->writer->writeAttribute('style:master-page-name', 'Default');
$this->writer->startElement('style:table-properties');
diff --git a/src/PhpSpreadsheet/Writer/Ods/Styles.php b/src/PhpSpreadsheet/Writer/Ods/Styles.php
index 448b1eff13..6bfdfb1b33 100644
--- a/src/PhpSpreadsheet/Writer/Ods/Styles.php
+++ b/src/PhpSpreadsheet/Writer/Ods/Styles.php
@@ -56,8 +56,17 @@ public function write(): string
$objWriter->writeElement('office:font-face-decls');
$objWriter->writeElement('office:styles');
- $objWriter->writeElement('office:automatic-styles');
- $objWriter->writeElement('office:master-styles');
+ $objWriter->startElement('office:automatic-styles');
+ $objWriter->startElement('style:page-layout');
+ $objWriter->writeAttribute('style:name', 'Mpm1');
+ $objWriter->endElement(); // style:page-layout
+ $objWriter->endElement(); // office:automatic-styles
+ $objWriter->startElement('office:master-styles');
+ $objWriter->startElement('style:master-page');
+ $objWriter->writeAttribute('style:name', 'Default');
+ $objWriter->writeAttribute('style:page-layout-name', 'Mpm1');
+ $objWriter->endElement(); //style:master-page
+ $objWriter->endElement(); //office:master-styles
$objWriter->endElement();
return $objWriter->getData();
diff --git a/tests/data/Writer/Ods/content-arrays.xml b/tests/data/Writer/Ods/content-arrays.xml
index a33b7dbfca..231036ee29 100644
--- a/tests/data/Writer/Ods/content-arrays.xml
+++ b/tests/data/Writer/Ods/content-arrays.xml
@@ -1,2 +1,49 @@
-11133
\ No newline at end of file
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+1
+
+
+1
+
+
+
+
+
+1
+
+
+3
+
+
+
+
+
+3
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/tests/data/Writer/Ods/content-empty.xml b/tests/data/Writer/Ods/content-empty.xml
index 84f4c23977..cb14ce7e53 100644
--- a/tests/data/Writer/Ods/content-empty.xml
+++ b/tests/data/Writer/Ods/content-empty.xml
@@ -3,7 +3,7 @@
-
+
diff --git a/tests/data/Writer/Ods/content-hidden-worksheet.xml b/tests/data/Writer/Ods/content-hidden-worksheet.xml
index 88a53257a1..1d89560505 100644
--- a/tests/data/Writer/Ods/content-hidden-worksheet.xml
+++ b/tests/data/Writer/Ods/content-hidden-worksheet.xml
@@ -3,10 +3,10 @@
-
+
-
+
diff --git a/tests/data/Writer/Ods/content-with-data.xml b/tests/data/Writer/Ods/content-with-data.xml
index db7d75a747..82209609f8 100644
--- a/tests/data/Writer/Ods/content-with-data.xml
+++ b/tests/data/Writer/Ods/content-with-data.xml
@@ -3,10 +3,10 @@
-
+
-
+
From ed158f20ebffa5003c9a0783d47e5228f17bf642 Mon Sep 17 00:00:00 2001
From: oleibman <10341515+oleibman@users.noreply.github.com>
Date: Sun, 15 Dec 2024 10:39:00 -0800
Subject: [PATCH 2/2] Update CHANGELOG.md
---
CHANGELOG.md | 1 +
1 file changed, 1 insertion(+)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index f567e658c6..c06cdf5893 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -26,6 +26,7 @@ and this project adheres to [Semantic Versioning](https://semver.org).
### Fixed
- More context options may be needed for http(s) image. [Php issue 17121](https://github.com/php/php-src/issues/17121) [PR #4276](https://github.com/PHPOffice/PhpSpreadsheet/pull/4276)
+- Several fixed to ODS Writer. [Issue #4261](https://github.com/PHPOffice/PhpSpreadsheet/issues/4261) [PR #4263](https://github.com/PHPOffice/PhpSpreadsheet/pull/4263) [PR #4264](https://github.com/PHPOffice/PhpSpreadsheet/pull/4264) [PR #4266](https://github.com/PHPOffice/PhpSpreadsheet/pull/4266)
## 2024-12-08 - 3.6.0