Re: FormatConditions AddCondition() using absolute cell reference issue

Hi Louie,

I seems that you are using some older version of Aspose.Cells. I tested your scenario using a simple template excel file and it works fine as the conditional formattings is set to my defined cell area with the reference cell formula1.

Kindly try the attached version (4.4.1.16).

Test Code:

//Instantiate Workbook object
Workbook workbook = new Workbook();
workbook.Open("d:\\test\\condfbook.xls");
Worksheet sheet = workbook.Worksheets[0];
//Create an empty conditional formatting in the first worksheet
ConditionalFormattings cfs = sheet.ConditionalFormattings;
int index = cfs.Add();
FormatConditions fcs = cfs[index];
//Set the conditional format range.
CellArea ca = new CellArea();
ca.StartRow = 0;
ca.EndRow = 10;
ca.StartColumn = 2;
ca.EndColumn = 2;
fcs.AddArea(ca);

//Add condition. since A1 cell has some integer value.
int conditionIndex = fcs.AddCondition(FormatConditionType.CellValue, OperatorType.LessThan, "=$A$1",null);

//Set the Font text color.
FormatCondition fc = fcs[conditionIndex];
fc.Style.Font.Color = Color.Red;
fc.Style.Font.IsBold = true;

//Save the Excel file
workbook.Save("d:\\test\\out_condfbook.xls", FileFormatType.Default);

Thank you.

Hi Louie,

I seems that you are using some older version of Aspose.Cells. I tested your scenario using a simple template excel file and it works fine as the conditional formattings is set to my defined cell area with the reference cell formula1.

Kindly try the attached version (4.4.1.16).

Test Code:

//Instantiate Workbook object
Workbook workbook = new Workbook();
workbook.Open("d:\\test\\condfbook.xls");
Worksheet sheet = workbook.Worksheets[0];
//Create an empty conditional formatting in the first worksheet
ConditionalFormattings cfs = sheet.ConditionalFormattings;
int index = cfs.Add();
FormatConditions fcs = cfs[index];
//Set the conditional format range.
CellArea ca = new CellArea();
ca.StartRow = 0;
ca.EndRow = 10;
ca.StartColumn = 2;
ca.EndColumn = 2;
fcs.AddArea(ca);

//Add condition. since A1 cell has some integer value.
int conditionIndex = fcs.AddCondition(FormatConditionType.CellValue, OperatorType.LessThan, "=$A$1",null);

//Set the Font text color.
FormatCondition fc = fcs[conditionIndex];
fc.Style.Font.Color = Color.Red;
fc.Style.Font.IsBold = true;

//Save the Excel file
workbook.Save("d:\\test\\out_condfbook.xls", FileFormatType.Default);

Thank you.

Hi Amjad,

Thanks for the prompt reply. :)

Best,

Louie