@John.He
We have been using hex color values, we didn’t use RGB color values. Our code is very close to your example and we still can’t find the reason. But another weird behavior that we discovered is, we have an enum class where defined the status names and color.
In section “Version A” class we defined the Hex color value that we expect for each status name, this is the original values that we have.
If you look at the section “Version B” class, we shift the Hex colors values that we already have in the class to some status name and the colors is working when we exported the Excel.
That mean for example, for the status “Passed”, we shift “E1E5E7” color instead “9CE78C” color in TestRunStatus class and when we export the excel it came out with green color that we want.
Also for status “Failed” and “In Progress”.
“Failed”, shift “9CE78C” color instead “E39191”, came out with red color that we expect when export.
“In Progress”, shift “E39191” color instead “9CE0E1”, came out with light blue color that we expect.
There is no logic with this replacement and we just trying everything and we noticed this behavior.
Although it has been temporarily solved, it is only a partial solution. Because we have some that are saved in the database. Shifting in color we run the risk of this issue occurring again and it is confusing.
I uploaded more detail about the code
Version A
public enum TestRunStatus implements EnumWithId {
PASSED(1, "Passed", "9CE78C"),
NOT_RUN(2, "Not Run", null),
INPROGRESS(3, "In Progress", "9CE0E1"),
FAILED(4, "Failed", "E39191"),
BLOCKED(5, "Blocked", "F8B275"),
NOT_APPLICABLE(6, "Not applicable", "C3C3C3");
}
Version B
public enum TestRunStatus implements EnumWithId {
PASSED(1, "Passed", "9CE0E1"),
NOT_RUN(2, "Not Run", null),
INPROGRESS(3, "In Progress", "E39191"),
FAILED(4, "Failed", "9CE78C"),
BLOCKED(5, "Blocked", "F8B275"),
NOT_APPLICABLE(6, "Not applicable", "C3C3C3");
private void setCellAreaBackgroundColorsForLookups(CellArea cellArea, String rangeName, Collection<?> options) {
if (AsposeCellsUtil.optionsHaveAtLeastOneColor(options)) { // options = [{name="Passed", color="9CE0E1"}]
FormatConditionCollection fcs = validationAndFormatting.getConditionalFormattingForRange(rangeName, options);
fcs.addArea(cellArea);
}
}
FormatConditionCollection getConditionalFormattingForRange(String rangeName, Collection<?> options) {
ConditionalFormattingCollection cf = worksheet.getConditionalFormattings();
Integer cfIndex = rangeNameToConditionalFormattingIndexMap.get(rangeName);
if (cfIndex == null) {
cfIndex = cf.add();
FormatConditionCollection fcs = cf.get(cfIndex);
createConditionalFormatting(fcs, options);
rangeNameToConditionalFormattingIndexMap.put(rangeName, cfIndex);
}
return worksheet.getConditionalFormattings().get(cfIndex);
}
private void createConditionalFormatting(FormatConditionCollection fcs, Collection<?> options) {
for (Object option : options) {
Pair<String, String> nameAndColor = createNameAndColorLookupPropertyDTO(option);
String color = nameAndColor.getRight(); // color = "9CE0E1"
String equals = nameAndColor.getLeft(); // equals = "Passed"
setConditionalFormattingConditionForColor(fcs, equals, color);
}
}
private static Pair<String, String> createNameAndColorLookupPropertyDTO(Object valueObject) {
if (valueObject != null) {
if (valueObject instanceof TestRunStatus) {
return new Pair<>(((TestRunStatus) valueObject).getName(), ((TestRunStatus) valueObject).getColor());
}
}
return null;
}
private void setConditionalFormattingConditionForColor(FormatConditionCollection fcs, String formula, String hexColorString) {
Color color = AsposeCellsUtil.hex2Color(hexColorString);
if (color != null) {
int ii = fcs.addCondition(FormatConditionType.CELL_VALUE, OperatorType.EQUAL, formula, null);
FormatCondition fc = fcs.get(ii);
Style ss = fc.getStyle();
ss.setBackgroundColor(color);
fc.setStyle(ss);
}
}