Skip to content

Conversation

@MarkBaker
Copy link
Member

@MarkBaker MarkBaker commented Mar 12, 2022

This is:

- [X] a bugfix
- [ ] a new feature

Checklist:

Why this change is needed?

This PR resolves the problem with writing a CF Header for each CF range, no matter how many rules there are for that range, rather than writing a single header for all ranges.

It does not appear that this has ever worked correctly, and that only writing a single CF range was supported before, but recent changes to provide examples of multiple CF ranges in a single worksheet have highlighted the problem, while a modification to the Xls Writer to support multiple ranges actually broke the CF Writer so that Excel issues a warning when the file is opened.

Now the code can also handle:

  • Using cell references for the rule value
  • Using string literals for the rule value
  • Using formula expressions for the rule value

None of these previously worked. All cell reference, string literal or formula expressions used as rule values were silently converted to integer 0

In the event of s formula expressions that Xls itself doesn't support (e.g. when they use an Excel function that isn't known to the BIFF format), the code defaults the condition to ptgInt +0 (=0) to avoid breaking the structure of the file.

MarkBaker added 3 commits March 12, 2022 20:54
…kground colour is still a problem, so that it's easy to verify that the rule is beng written correctly
… for conditional formatting rules in the Xls file save

The code is ugly as sin; but it works... I'll do some refactoring and cleaning later (once I've had some sleep, because I'm stupidly still working on this at 3am)

The main remaining issue is formulae that can't be parsed in BIFF8 files; e.g. formulae that use functions that aren't available. In this case, all CF in that worksheet is corrupted, and the file errors when opened, so it is a serious issue. The ISODD()/ISEVEN example in 07_Expression_Comparisons.php uses these, so I've temporarily commented out setting that CF range until I've solved that problem. There are other limitations listed in the BIFF documentation; but they're harder to detect.
I've also left a couple of debug statements in the code to display these formula errors: I'll remove them once I've resolved the issue.
@MarkBaker
Copy link
Member Author

MarkBaker commented Mar 13, 2022

I guess I'll also need to create a series of unit tests for CF Writing both for Xlsx and Xls; create, save, reload and verify that they're as written.

That's not going to be easy, as the Xls Reader doesn't read conditional formatting :-(

@MarkBaker MarkBaker merged commit 004de10 into master Mar 13, 2022
@MarkBaker MarkBaker deleted the Resolve-CF-Issues-with-Xls-Writer branch March 13, 2022 10:48
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.

2 participants