Skip to content

Commit b43947f

Browse files
authored
Merge pull request #4101 from oleibman/issue4099
Ods Reader Allow Omission of Some Page Settings Tags
2 parents 8225096 + debb177 commit b43947f

File tree

4 files changed

+47
-16
lines changed

4 files changed

+47
-16
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ and this project adheres to [Semantic Versioning](https://semver.org).
2626
### Fixed
2727

2828
- Add Sheet may leave Active Sheet uninitialized. [Issue #4112](https://github.com/PHPOffice/PhpSpreadsheet/issues/4112) [PR #4114](https://github.com/PHPOffice/PhpSpreadsheet/pull/4114)
29+
- Reference to Defined Name Specifying Worksheet. [Issue #206](https://github.com/PHPOffice/PhpSpreadsheet/issues/296) [PR #4096](https://github.com/PHPOffice/PhpSpreadsheet/pull/4096)
30+
- Xls Reader Print/Show Gridlines. [Issue #912](https://github.com/PHPOffice/PhpSpreadsheet/issues/912) [PR #4098](https://github.com/PHPOffice/PhpSpreadsheet/pull/4098)
31+
- ODS Reader Allow Omission of Page Settings Tags. [Issue #4099](https://github.com/PHPOffice/PhpSpreadsheet/issues/4099) [PR #4101](https://github.com/PHPOffice/PhpSpreadsheet/pull/4101)
2932

3033
## 2024-07-24 - 2.2.0
3134

src/PhpSpreadsheet/Reader/Ods/PageSettings.php

+16-16
Original file line numberDiff line numberDiff line change
@@ -55,22 +55,22 @@ private function readPageSettingStyles(DOMDocument $styleDom): void
5555

5656
foreach ($styles as $styleSet) {
5757
$styleName = $styleSet->getAttributeNS($this->stylesNs, 'name');
58-
$pageLayoutProperties = $styleSet->getElementsByTagNameNS($this->stylesNs, 'page-layout-properties')[0];
59-
$styleOrientation = $pageLayoutProperties->getAttributeNS($this->stylesNs, 'print-orientation');
60-
$styleScale = $pageLayoutProperties->getAttributeNS($this->stylesNs, 'scale-to');
61-
$stylePrintOrder = $pageLayoutProperties->getAttributeNS($this->stylesNs, 'print-page-order');
62-
$centered = $pageLayoutProperties->getAttributeNS($this->stylesNs, 'table-centering');
63-
64-
$marginLeft = $pageLayoutProperties->getAttributeNS($this->stylesFo, 'margin-left');
65-
$marginRight = $pageLayoutProperties->getAttributeNS($this->stylesFo, 'margin-right');
66-
$marginTop = $pageLayoutProperties->getAttributeNS($this->stylesFo, 'margin-top');
67-
$marginBottom = $pageLayoutProperties->getAttributeNS($this->stylesFo, 'margin-bottom');
68-
$header = $styleSet->getElementsByTagNameNS($this->stylesNs, 'header-style')[0];
69-
$headerProperties = $header->getElementsByTagNameNS($this->stylesNs, 'header-footer-properties')[0];
70-
$marginHeader = isset($headerProperties) ? $headerProperties->getAttributeNS($this->stylesFo, 'min-height') : null;
71-
$footer = $styleSet->getElementsByTagNameNS($this->stylesNs, 'footer-style')[0];
72-
$footerProperties = $footer->getElementsByTagNameNS($this->stylesNs, 'header-footer-properties')[0];
73-
$marginFooter = isset($footerProperties) ? $footerProperties->getAttributeNS($this->stylesFo, 'min-height') : null;
58+
$pageLayoutProperties = $styleSet->getElementsByTagNameNS($this->stylesNs, 'page-layout-properties')->item(0);
59+
$styleOrientation = $pageLayoutProperties?->getAttributeNS($this->stylesNs, 'print-orientation');
60+
$styleScale = $pageLayoutProperties?->getAttributeNS($this->stylesNs, 'scale-to');
61+
$stylePrintOrder = $pageLayoutProperties?->getAttributeNS($this->stylesNs, 'print-page-order');
62+
$centered = $pageLayoutProperties?->getAttributeNS($this->stylesNs, 'table-centering');
63+
64+
$marginLeft = $pageLayoutProperties?->getAttributeNS($this->stylesFo, 'margin-left');
65+
$marginRight = $pageLayoutProperties?->getAttributeNS($this->stylesFo, 'margin-right');
66+
$marginTop = $pageLayoutProperties?->getAttributeNS($this->stylesFo, 'margin-top');
67+
$marginBottom = $pageLayoutProperties?->getAttributeNS($this->stylesFo, 'margin-bottom');
68+
$header = $styleSet->getElementsByTagNameNS($this->stylesNs, 'header-style')->item(0);
69+
$headerProperties = $header?->getElementsByTagNameNS($this->stylesNs, 'header-footer-properties')?->item(0);
70+
$marginHeader = $headerProperties?->getAttributeNS($this->stylesFo, 'min-height');
71+
$footer = $styleSet->getElementsByTagNameNS($this->stylesNs, 'footer-style')->item(0);
72+
$footerProperties = $footer?->getElementsByTagNameNS($this->stylesNs, 'header-footer-properties')?->item(0);
73+
$marginFooter = $footerProperties?->getAttributeNS($this->stylesFo, 'min-height');
7474

7575
$this->pageLayoutStyles[$styleName] = (object) [
7676
'orientation' => $styleOrientation ?: PageSetup::ORIENTATION_DEFAULT,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace PhpOffice\PhpSpreadsheetTests\Reader\Ods;
6+
7+
use PhpOffice\PhpSpreadsheet\Reader\Ods as OdsReader;
8+
use PHPUnit\Framework\TestCase;
9+
10+
class Issue4099Test extends TestCase
11+
{
12+
private string $file = 'tests/data/Reader/Ods/issue.4099.ods';
13+
14+
public function testNoHeaderFooterStyle(): void
15+
{
16+
// header-style and footer-style are missing in styles.xml
17+
$zipFile = 'zip://' . $this->file . '#styles.xml';
18+
$contents = (string) file_get_contents($zipFile);
19+
self::assertStringContainsString('page-layout ', $contents);
20+
self::assertStringNotContainsString('header-style', $contents);
21+
self::assertStringNotContainsString('footer-style', $contents);
22+
$reader = new OdsReader();
23+
$spreadsheet = $reader->load($this->file);
24+
$sheet = $spreadsheet->getActiveSheet();
25+
self::assertSame('FirstCell', $sheet->getCell('A1')->getValue());
26+
$spreadsheet->disconnectWorksheets();
27+
}
28+
}

tests/data/Reader/Ods/issue.4099.ods

8.68 KB
Binary file not shown.

0 commit comments

Comments
 (0)