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

The order of setting a border can corrupt the style. #304

Open
DevonReynolds opened this issue Dec 12, 2024 · 2 comments
Open

The order of setting a border can corrupt the style. #304

DevonReynolds opened this issue Dec 12, 2024 · 2 comments
Assignees
Labels
enhancement New feature or request ready to close Pull request has been answered or implemented & is pending closure testing Functionality has been implemented in development branch and is pending a merge into main

Comments

@DevonReynolds
Copy link

It seems excel expects the border to be in the order left, right, top, bottom, diagonal in the styles.xml file. If it's not in this order then excel will give an error saying the style is corrupted. The order of the styles in OpenXLSX is determined by the order they are set in code. So if the Top, Bottom are set then the Right is set, the file cannot be opened in excel.

Works
auto leftBorder = borders.create(); borders[leftBorder].setOutline(true); borders[leftBorder].setLeft(OpenXLSX::XLLineStyleThin, OpenXLSX::XLColor("ff000000")); borders[leftBorder].setTop(OpenXLSX::XLLineStyleThin, OpenXLSX::XLColor("ff000000")); borders[leftBorder].setBottom(OpenXLSX::XLLineStyleThin, OpenXLSX::XLColor("ff000000"));

Corrupts Style
auto leftBorder = borders.create(); borders[leftBorder].setOutline(true); borders[leftBorder].setTop(OpenXLSX::XLLineStyleThin, OpenXLSX::XLColor("ff000000")); borders[leftBorder].setBottom(OpenXLSX::XLLineStyleThin, OpenXLSX::XLColor("ff000000")); borders[leftBorder].setLeft(OpenXLSX::XLLineStyleThin, OpenXLSX::XLColor("ff000000"));

@aral-matrix
Copy link
Collaborator

Thank you for reporting this, as it doesn't matter in the slightest to OpenXLSX, this will be an easy fix - I'll just add some additional sorting logic for these elements of XLStyles. Will report here when it's patched. Please feel welcome to open new issues for anything similar that you find.

@aral-matrix
Copy link
Collaborator

Okay, this was not quite as trivial as I thought, mostly because of the logic of how to sort against a predefined list of tag names, and how to respect (potential) whitespace nodes in the XML.
Anyways, please have a look at 77f4370 and if you could do some extensive testing that would be appreciated - I am sure there are other style elements where MS Office enforces a strict sequence - but now I have the tool & can easily implement fixed sequences.

@aral-matrix aral-matrix added testing Functionality has been implemented in development branch and is pending a merge into main ready to close Pull request has been answered or implemented & is pending closure labels Dec 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request ready to close Pull request has been answered or implemented & is pending closure testing Functionality has been implemented in development branch and is pending a merge into main
Projects
None yet
Development

No branches or pull requests

2 participants