The style font.setColor in the conditional format is invalid

Created a conditional format using the interface, sheet.getConditionalFormattings().add(), The default font style color inside is black condition. getStyle(). getFont()

To clear the style settings inside, call font. setColor (Color. getEmpty()); No effect
The result is still black

@xhaixia

It seems you are experiencing an issue with setting the font color in a conditional formatting rule using Aspose.Cells. When you attempt to clear the font color by calling font.setColor(Color.getEmpty()), it does not have the desired effect, and the font remains black.

To address this, you can try explicitly setting the font color to a different color instead of using Color.getEmpty(). For example, you can set it to Color.Transparent or any other color that suits your needs. Here’s a code snippet that demonstrates how to set the font color in a conditional formatting rule:

// Assuming you have already created a Workbook and Worksheet
int index = sheet.ConditionalFormattings.Add();
FormatConditionCollection fcs = sheet.ConditionalFormattings[index];

// Define the range for the conditional formatting
CellArea ca = new CellArea();
ca.StartRow = 0;
ca.EndRow = 5;
ca.StartColumn = 0;
ca.EndColumn = 3;
fcs.AddArea(ca);

// Add a condition
int conditionIndex = fcs.AddCondition(FormatConditionType.CellValue, OperatorType.Between, "50", "100");
FormatCondition fc = fcs[conditionIndex];

// Set the font style
fc.Style.Font.IsItalic = true;
fc.Style.Font.IsBold = true;
fc.Style.Font.IsStrikeout = true;
fc.Style.Font.Underline = FontUnderlineType.Double;

// Set the font color to a different color
fc.Style.Font.Color = Color.Transparent; // or any other color

// Save the workbook
workbook.Save("output.xlsx");

In this example, the font color is set to Color.Transparent, which should effectively clear the previous color setting. If you still encounter issues, please ensure that the conditional formatting is being applied correctly and that there are no other conflicting styles.

If you need further assistance, feel free to ask!

What I need is to clear the color settings instead of giving fixed color settings. The reason for doing this is to match the unset format of the conditional format in Excel
image.png (54.0 KB)

@xhaixia
After adding the conditional format on the latest version v25.1 without any settings, you will get the expected result. Please review the result file and screenshot. result.zip (36.0 KB)

The sample code as follows:

Workbook wb = new Workbook();
Worksheet sheet = wb.getWorksheets().get(0);

// Assuming you have already created a Workbook and Worksheet
int index = sheet.getConditionalFormattings().add();
FormatConditionCollection fcs = sheet.getConditionalFormattings().get(index);

// Define the range for the conditional formatting
CellArea ca = new CellArea();
ca.StartRow = 0;
ca.EndRow = 5;
ca.StartColumn = 0;
ca.EndColumn = 3;
fcs.addArea(ca);

// Add a condition
int conditionIndex = fcs.addCondition(FormatConditionType.CELL_VALUE, OperatorType.BETWEEN, "50", "100");
FormatCondition fc = fcs.get(conditionIndex);	

// Save the workbook
wb.save(filePath + "out_java.xlsx");

Hope helps a bit.

The final generated Excel is indeed fine, but the font color corresponding to the style in the conditional format obtained in the program code is still black (fc. getStyle(). getFont()), which is inconsistent with the actual effect. How can this maintain the correct final effect
image.png (26.2 KB)

Is there any marking where the font color has not been actively set

@xhaixia
Please refer to the following example code to check if the style properties have been modified.

Workbook wb = new Workbook();
Worksheet sheet = wb.getWorksheets().get(0);

// Assuming you have already created a Workbook and Worksheet
int index = sheet.getConditionalFormattings().add();
FormatConditionCollection fcs = sheet.getConditionalFormattings().get(index);

// Define the range for the conditional formatting
CellArea ca = new CellArea();
ca.StartRow = 0;
ca.EndRow = 5;
ca.StartColumn = 0;
ca.EndColumn = 3;
fcs.addArea(ca);

// Add a condition
int conditionIndex = fcs.addCondition(FormatConditionType.CELL_VALUE, OperatorType.BETWEEN, "50", "100");
FormatCondition fc = fcs.get(conditionIndex);

//check style properties
System.out.println(fc.getStyle().isModified(StyleModifyFlag.FONT_COLOR));

// Save the workbook
wb.save(filePath + "out_java.xlsx");

The output result:

false

Hope helps a bit.