Fix corrupted file with conditional formatting and hyperlinks #2803
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
I faced the issue with stream writer creating corrupted file. Through some experiments and inspecting differences between the file created by the library and handmade file using Microsoft Excel I found out that the corruption appears when you use conditional formatting together with hyperlinks. The issue is that the order of blocks in the worksheet is wrong. This pull request solves this issue.
Test plan
First we create file using Microsoft Excel with links and some conditional formatting eg.


=MOD(ROW();2)=0
to color every odd row:Then we inspect the file and see that the order in sheet is: first conditional formatting, second hyperlinks
After that we create similar file using the library:
If we open the resulting file with Excel we see the error:
If we inspect the underlying xml file we see that the order is different:
So then we can change the order in
worksheet-writer.js
and try the script again:The file generates successfully and opens in Excel: