PHPOffice / PhpSpreadsheet

A pure PHP library for reading and writing spreadsheet files
https://phpspreadsheet.readthedocs.io
MIT License
13.22k stars 3.41k forks source link

Reader\Xlsx - showGridlines option is set when shouldn't #912

Closed xklid101 closed 1 month ago

xklid101 commented 5 years ago

This is:

- [x] a bug report
- [ ] a feature request
- [ ] **not** a usage question (ask them on https://stackoverflow.com/questions/tagged/phpspreadsheet or https://gitter.im/PHPOffice/PhpSpreadsheet)

What is the expected behavior?

when reading - do not set xml attribute showGridlines from element sheetView to true when xml attribute gridlinesSet from element printOptions is true

What is the current behavior?

when reading - xml attribute showGridlines from element sheetView is set to true when xml attribute gridlinesSet from element printOptions is true

What are the steps to reproduce?

Just read any xlsx file saved in a way that has gridlines invisible for sheetView (showGridLines="false") and contains printOptions element with attribute gridLinesSet="true"

e.g. in sheet1.xml

...
<sheetView showGridLines="false" showRowColHeaders="1" tabSelected="0" workbookViewId="0" zoomScale="55" zoomScaleNormal="55">
    <selection activeCell="B17" sqref="B17"/>
</sheetView>
...
...
<printOptions gridLines="false" gridLinesSet="true" headings="true" horizontalCentered="false" verticalCentered="false"/>
...

after reading this file, the result created with phpspreadsheet will allways have showGridLines="true" in sheetView

and it is because of this part of code in reader (mainly the first "if" block) https://github.com/PHPOffice/PhpSpreadsheet/blob/1.6.0/src/PhpSpreadsheet/Reader/Xlsx.php#L880-L885

and according to some specification i've found, the code highlighted should change into this:

if (self::boolean((string) $xmlSheet->printOptions['gridLines']) && self::boolean((string) $xmlSheet->printOptions['gridLinesSet'])) {
    $docSheet->setPrintGridlines(true);
}

Which versions of PhpSpreadsheet and PHP are affected?

phpspreadsheet 1.6.0 any php version

Specification that i've found can be downloaded here https://www.iso.org/standard/71691.html

and contains

...
gridLines (Print
Grid Lines)
Used in conjunction with gridLinesSet. If both gridLines and gridlinesSet are true , then
grid lines shall print. Otherwise, they shall not (i.e., one or both have false values).
The possible values for this attribute are defined by the W3C XML Schema boolean
datatype.

gridLinesSet (Grid
Lines Set)
Used in conjunction with gridLines. If both gridLines and gridLinesSet are true , then
grid lines shall print. Otherwise, they shall not (i.e., one or both have false values).
The possible v
...

so nothing about sheetView, but only about printing

stale[bot] commented 5 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If this is still an issue for you, please try to help by debugging it further and sharing your results. Thank you for your contributions.

oleibman commented 1 month ago

Reopening. It seems a bit odd, but legitimate. Expect a fix in a day or two.