Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conditional and table formatting support for html #4412

Merged
merged 2 commits into from
Mar 27, 2025

Conversation

mikkokoo
Copy link
Contributor

@mikkokoo mikkokoo commented Mar 19, 2025

This is:

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

Checklist:

  • Changes are covered by unit tests
    • Changes are covered by existing unit tests
    • New unit tests have been added
  • Code style is respected
  • Commit message explains why the change is made (see https://github.com/erlang/otp/wiki/Writing-good-commit-messages)
  • CHANGELOG.md contains a short summary of the change and a link to the pull request if applicable
  • Documentation is updated as necessary

Why this change is needed?

Conditional and table formatting support for html writer were needed to provide better html output for processed files.

Fix #1375.

@mikkokoo mikkokoo marked this pull request as ready for review March 19, 2025 12:40
@oleibman
Copy link
Collaborator

Here is something like what I would like to see for HtmlTableFormatWithConditionalTest.
HtmlTableFormatWithConditionalTest.zip

@mikkokoo
Copy link
Contributor Author

I did some profiling and found out that the getHashCode functions in Style/ get called a lot. They make the conditional formatting pretty slow. I managed to cache the hash code so that the execution time dropped by 75%.

@oleibman Should I commit that to this PR (I think yes) or make another pull request after this one?

10 files changed, 242 insertions(+), 61 deletions(-)

@mikkokoo mikkokoo force-pushed the master branch 2 times, most recently from 4272f4d to d542036 Compare March 24, 2025 12:56
@oleibman
Copy link
Collaborator

Please make a separate PR for your HashCode improvements.


public static function colourScaleProvider(): array
{
return [
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is still an overwhelmingly large number of tests. Can you model it after the others and just test a few "interesting" cells in each row, and only for the data you're looking for (background color and value).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is the test of different color scale formulas. There has to be quite a few data points to have meaningful results as the style is the only measurable data. They are all interesting. I'd say this is the bare minimum.


public function testConditionalFormattingRulesHtml(): void
{
$expectedMatches = [
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, this is just too many tests for me to absorb. Please just choose a representative sample. Maybe a couple from column 1 (all of this column seems to match whatever test it needs), the matching cell from column 2, one or two non-matching cells from column 2, and one or two cells from column 3 (these might be a little trickier because conditional formatting doesn't apply to them). It is not that the tests I'm asking you to remove aren't worthwhile - they most decidedly are. For that reason, I would suggest commenting them out rather than deleting them. I think the "missing" tests are better handled by also creating new samples, so that we can confirm visually that the html matches the original xlsx. I will add a comment to your ticket later on how that might be done.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a different code path for each test and they use a different conditional case. They are lightning fast as they only check from the same loaded data. I don't understand the rationale of how removing some of them makes the regression testing better.

Making the xlsx to samples makes sense. But I'd still keep these.

@oleibman
Copy link
Collaborator

As discussed above, I would like you to use your xlsx files for both unit tests and samples. Here is how you might go about it.
htmlcondtosamples.zip

@oleibman
Copy link
Collaborator

Thank you for all the extra work. I need to do a final review, but should be able to merge this in the next day or two.

@oleibman oleibman added this pull request to the merge queue Mar 27, 2025
Merged via the queue into PHPOffice:master with commit f52ae20 Mar 27, 2025
13 of 14 checks passed
@oleibman
Copy link
Collaborator

Thank you for your contribution. A complicated but much needed addition. I shall look forward to seeing what you found out about HashCode.

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.

PDF-Generation don't respect condtional formatting
2 participants