diff --git a/CHANGELOG.md b/CHANGELOG.md index 3420e60a45..fdbc602ab6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -34,7 +34,8 @@ and this project adheres to [Semantic Versioning](https://semver.org). - Print Area and Row Break. [Issue #1275](https://github.com/PHPOffice/PhpSpreadsheet/issues/1275) [PR #4450](https://github.com/PHPOffice/PhpSpreadsheet/pull/4450) - Copy Styles after insertNewColumnBefore. [Issue #1425](https://github.com/PHPOffice/PhpSpreadsheet/issues/1425) [PR #4468](https://github.com/PHPOffice/PhpSpreadsheet/pull/4468) - Xls Writer Treat Hyperlink Starting with # as Internal. [Issue #56](https://github.com/PHPOffice/PhpSpreadsheet/issues/56) [PR #4453](https://github.com/PHPOffice/PhpSpreadsheet/pull/4453) -- ODS Handling of Ceiling and Floor. [Issue #407](https://github.com/PHPOffice/PhpSpreadsheet/issues/407) [PR #4466](https://github.com/PHPOffice/PhpSpreadsheet/pull/4466) +- ODS Handling of Ceiling and Floor. [Issue #477](https://github.com/PHPOffice/PhpSpreadsheet/issues/407) [PR #4466](https://github.com/PHPOffice/PhpSpreadsheet/pull/4466) +- Xlsx Reader Do Not Process Printer Settings for Dataonly. [Issue #4477](https://github.com/PHPOffice/PhpSpreadsheet/issues/4477) [PR #4480](https://github.com/PHPOffice/PhpSpreadsheet/pull/4480) ## 2025-04-16 - 4.2.0 diff --git a/src/PhpSpreadsheet/Reader/Xlsx.php b/src/PhpSpreadsheet/Reader/Xlsx.php index b13114ab47..b60bf047bf 100644 --- a/src/PhpSpreadsheet/Reader/Xlsx.php +++ b/src/PhpSpreadsheet/Reader/Xlsx.php @@ -2231,6 +2231,9 @@ private function readFormControlProperties(Spreadsheet $excel, string $dir, stri /** @param mixed[][][][] $unparsedLoadedData */ private function readPrinterSettings(Spreadsheet $excel, string $dir, string $fileWorksheet, Worksheet $docSheet, array &$unparsedLoadedData): void { + if ($this->readDataOnly) { + return; + } $zip = $this->zip; if ($zip->locateName(dirname("$dir/$fileWorksheet") . '/_rels/' . basename($fileWorksheet) . '.rels') === false) { return; diff --git a/tests/PhpSpreadsheetTests/Reader/Xlsx/Issue4477Test.php b/tests/PhpSpreadsheetTests/Reader/Xlsx/Issue4477Test.php new file mode 100644 index 0000000000..814e0daf79 --- /dev/null +++ b/tests/PhpSpreadsheetTests/Reader/Xlsx/Issue4477Test.php @@ -0,0 +1,73 @@ +tempfile !== '') { + unlink($this->tempfile); + $this->tempfile = ''; + } + } + + public function testDataonlyNoPrinter(): void + { + // Need to ignore printer settings when Read Dataonly + $infile = 'tests/data/Reader/XLSX/issue.4477.disclaimer.xlsx'; + $zip = new ZipArchive(); + if ($zip->open($infile) !== true) { + self::fail("failed to open $infile"); + } + $num = $zip->numFiles; + $foundPrinter = $foundWorksheet = false; + for ($i = 0; $i < $num; ++$i) { + $filename = (string) $zip->getNameIndex($i); + if (str_contains($filename, 'printer')) { + $foundPrinter = true; + } elseif ($filename === 'xl/worksheets/sheet1.xml') { + $foundWorksheet = true; + } + } + $zip->close(); + self::assertTrue($foundPrinter); + self::assertTrue($foundWorksheet); + + $reader = new XlsxReader(); + $reader->setReadDataOnly(true); + $spreadsheet = $reader->load($infile); + $writer = new XlsxWriter($spreadsheet); + $this->tempfile = File::temporaryFileName(); + $writer->save($this->tempfile); + $spreadsheet->disconnectWorksheets(); + + $zip = new ZipArchive(); + if ($zip->open($this->tempfile) !== true) { + self::fail("failed to open {$infile}"); + } + $num = $zip->numFiles; + $foundPrinter = $foundWorksheet = false; + for ($i = 0; $i < $num; ++$i) { + $filename = (string) $zip->getNameIndex($i); + if (str_contains($filename, 'printer')) { + $foundPrinter = true; + } elseif ($filename === 'xl/worksheets/sheet1.xml') { + $foundWorksheet = true; + } + } + $zip->close(); + self::assertFalse($foundPrinter); + self::assertTrue($foundWorksheet); + } +} diff --git a/tests/data/Reader/XLSX/issue.4477.disclaimer.xlsx b/tests/data/Reader/XLSX/issue.4477.disclaimer.xlsx new file mode 100644 index 0000000000..619e8093c8 Binary files /dev/null and b/tests/data/Reader/XLSX/issue.4477.disclaimer.xlsx differ