Free Support Forum - aspose.com

Conditional formattings

Hello,

Did something change in setting a conditional formatting ?

It worked in the past, but now I'm receiving an error !

--> received Java exception "java.lang.IllegalArgumentException: Invalid
Condition formatting: index 0: conditionally formatted C" when calling
method "save" with signature "(Ljava.lang.String;I)V" in class
"com.aspose.cells.Workbook".

Thanks !

Hi,

Well, I tested conditional formattings feature using Aspose.Cells for java APIs and it works fine.

Following is my sample code:

//Instantiating an Workbook object
Workbook workbook = new Workbook();
Worksheet sheet = workbook.getSheet(0);
ConditionalFormattings cfs = sheet.getConditionalFormattings();


//The first method:adds an empty conditional formatting
int index = cfs.add();
FormatConditions fcs = cfs.get(index);


//Sets the conditional format range.
fcs.addArea(new CellArea(0,0,0,0));
fcs.addArea(new CellArea(1,1,1,1));
fcs.addArea(new CellArea(2,2,5,5));


//Sets condition formulas.
int conditionIndex = fcs.addFormatCondition(FormatConditionType.CELL_VALUE,OperatorType.BETWEEN,"=A2","100");
FormatCondition fc = fcs.getFormatCondition(conditionIndex);
int conditionIndex2 = fcs.addFormatCondition(FormatConditionType.CELL_VALUE,OperatorType.BETWEEN,"50","100");

// The second method
int formatCondtionsIndex = cfs.add(new CellArea(9,1,10,1),FormatConditionType.CELL_VALUE, OperatorType.BETWEEN,"=A1","100");

workbook.save("E:\\Files\\conditionalformattings.xls");

Which version of Aspose.Cells for java you are using. Please try the attached version.

If you still find the problem, post you sample code here.

Thank you.

Thanks,

I didn't add a cellarea !?

Is it necesary, or can you apply a conditional format for the whole sheet ?

Hi,

Yes, you have to define the area.

Thank you.

Hi,

Please define the area for the whole sheet.

int formatCondtionsIndex = cfs.add(new CellArea(0,0,65535,255),FormatConditionType.CELL_VALUE, OperatorType.BETWEEN,"0","100");

or

int formatCondtionsIndex = cfs.add(new CellArea(0,0,cells.getMaxRow(),cells.getMaxColumn()),FormatConditionType.CELL_VALUE, OperatorType.BETWEEN,"0","100");

Do I have to add an area before I can add a formatCondition ?

Hi,

Thanks for considering Aspose.

Well, It's up to you, you may also add the formatcondition first then add the cell area range.

Thank you.

Ok, works fine !

Thanks.