Skip to content

Conversation

oleibman
Copy link
Collaborator

Fix #4539. Conditional Formatting was recently added to Html Writer. It works fine when not using inline Css. However, when using inline Css, the code inadvertently added 2 different style attributes (one for the unconditional style and one for the conditional style) to the same cell. This is not valid html, and results in losing the conditional styling. This PR combines the two style attributes into one, which will now come after the class, colspan, and rowspan attributes.

Aside from the new tests, this PR changes an unusually large number of existing tests. While this might normally be considered a red flag, it is not a problem here. All of the changes involve merely changing the order of attributes within html tags; none of them affect how the generated html would appear in a browser.

This is:

  • a bugfix
  • a new feature
  • refactoring
  • additional unit tests

Checklist:

Fix PHPOffice#4539. Conditional Formatting was recently added to Html Writer. It works fine when not using inline Css. However, when using inline Css, the code inadvertently added 2 different `style` attributes (one for the unconditional style and one for the conditional style) to the same cell. This is not valid html, and results in losing the conditional styling. This PR combines the two `style` attributes into one, which will now come after the `class`, `colspan`, and `rowspan` attributes.

Aside from the new tests, this PR changes an unusually large number of existing tests. While this might normally be considered a red flag, it is not a problem here. All of the changes involve merely changing the order of attributes within html tags; none of them affect how the generated html would appear in a browser.
@ccchapman
Copy link

Confirming this fixes my issue. Thank you for fixing so quickly.

oleibman added 3 commits July 16, 2025 22:11
Xlsx conditional styles cannot be used to change alignment, nor font family, nor font size.

Conditional::getStyle currently allocates a new style as an unconditional style; it is changed to do so a conditional ctyle.

Border should not be conditionally merged if borderStyle is OMIT.

Inline Css was generating `class="gridlines gridlinesp"` for all cells. It is changed to use the worksheet settings to decide which classes to use.
Using baseStyle directly can lead to the by-reference problems associated with Cell and Style.
Do not override base style if conditional style indicates BORDER_OMIT.

Do not export BORDER_NONE color 0 for conditional; same approach is already taken for unconditional.
@oleibman
Copy link
Collaborator Author

@ccchapman Thank you for confirming. As you can see, I have made additional changes to fix pre-existing problems that I've encountered while doing more extensive testing. I think I am done with those now. It is very unlikely that the new changes will adversely affect you, but please test again if you can.

@ccchapman
Copy link

@oleibman Thank you. I just tested 3cc82a9 with a more complicated real-world spreadsheet. It works perfectly.

@oleibman oleibman enabled auto-merge July 22, 2025 04:23
@oleibman oleibman added this pull request to the merge queue Jul 22, 2025
Merged via the queue into PHPOffice:master with commit adb7459 Jul 22, 2025
13 of 14 checks passed
@oleibman oleibman deleted the issue4539 branch July 22, 2025 04:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

XLSX reader HTML writer does not support conditional formatting if using inline CSS

2 participants