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

fix: apply colors from conditional formatting #6824

Merged
merged 2 commits into from
Nov 18, 2024

Conversation

sissbruecker
Copy link
Contributor

@sissbruecker sissbruecker commented Nov 14, 2024

Fixes logic for retrieving text and background color from formatting rules and adds handling of indexed and RGB colors.

Fixes #6819

Comment on lines +420 to +423
declaredMethod = rule.getClass().getDeclaredMethod("getDxf",
boolean.class);
declaredMethod.setAccessible(true);
realRule = (CTCfRule) declaredMethod.invoke(rule);
CTDxf dxf = workbook.getStylesSource().getCTStylesheet().getDxfs()
.getDxfArray((int) realRule.getDxfId());
return dxf;
return (CTDxf) declaredMethod.invoke(rule, false);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the main part of the fix which allows to retrieve the font and background pattern config from the conditional formatting rule.

@@ -288,6 +288,11 @@ public String getBackgroundColorCSS(ConditionalFormattingRule rule) {

// CF rules have tint in bgColor but not the XSSFColor.
return styleColor(themeColor, bgColor.getTint());
} else if (bgColor.isSetIndexed()) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This allows using an indexed color as font / background color.

@@ -14,16 +14,19 @@ public class ColorConverterUtil implements Serializable {

public static String toRGBA(byte[] argb) {
int rgba[] = new int[3];
for (int i = 1; i < argb.length; i++) {
boolean hasAlpha = argb.length == 4;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Apparently XSSFColor can either hold a byte array with three elements for an RGB color or an array with four elements for an ARGB color. This fixes the logic to also handle RGB byte arrays.

@sissbruecker sissbruecker marked this pull request as ready for review November 15, 2024 08:38
@sissbruecker sissbruecker enabled auto-merge (squash) November 18, 2024 10:04
Copy link

sonarcloud bot commented Nov 18, 2024

@sissbruecker sissbruecker merged commit 6551f2e into main Nov 18, 2024
5 checks passed
@sissbruecker sissbruecker deleted the fix/spreadsheet-conditional-format-colors branch November 18, 2024 10:58
vaadin-bot pushed a commit that referenced this pull request Nov 18, 2024
sissbruecker added a commit that referenced this pull request Nov 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Vaadin Flow Spreadsheet conditional formatting doesn't apply colors to a cell style
3 participants