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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

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

Copy link

sonarcloud bot commented Nov 14, 2024

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
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
1 participant