We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Conditional formats and GetDisplayStyle is not behaving correctly with strings and negative numbers

Hi,



We’ve found a problem with GetDisplayStyle() with conditional format for the following test case:



--------------------------------------

var grid = (new Workbook()).Worksheets[0];



var cellA1 = grid.Cells[0, 0];

var lessThanValue = “-5”;

var greaterThanValue = “70”;

var lessThanColor = Color.Red;

var greaterThanColor = Color.Green;

var betweenColor = Color.Yellow;



// Value of this (30) is between the lessThan (-5) and greaterThan (70) values

// Note: that this test passes if the integer 30 is used instead

cellA1.PutValue(“30”);



var index = grid.ConditionalFormattings.Add();

var formatCondition = grid.ConditionalFormattings[index];



var cellArea = new CellArea() { StartRow = 0, EndRow = 0, StartColumn = 0, EndColumn = 0 };



formatCondition.AddArea(cellArea);



var lessThanConditionIndex = formatCondition.AddCondition(FormatConditionType.CellValue, OperatorType.LessThan, lessThanValue, “”);

var lessThanCondition = formatCondition[lessThanConditionIndex];



lessThanCondition.Style.Font.Color = lessThanColor;



var greaterThanConditionIndex = formatCondition.AddCondition(FormatConditionType.CellValue, OperatorType.GreaterThan, greaterThanValue, “”);

var greaterThanCondition = formatCondition[greaterThanConditionIndex];



greaterThanCondition.Style.Font.Color = greaterThanColor;



var betweenConditionIndex = formatCondition.AddCondition(FormatConditionType.CellValue, OperatorType.Between, lessThanValue, greaterThanValue);

var betweenCondition = formatCondition[betweenConditionIndex];



betweenCondition.Style.Font.Color = betweenColor;



cellA1.SetStyle(cellA1.GetDisplayStyle());



// this assert should pass

Debug.Assert(cellA1.Style.Font.Color.ToArgb() == betweenColor.ToArgb());

--------------------------------------



Is this a bug?



Thank you,

-Steve

Hi Steve,

Thanks for giving us the details with sample code,

We will figure out the issue soon.

Thank you.

Hi Steve,

If you want to set integer 30 to cell , please use Cell.PutValue(30) not Cell.PutValue("30").

If you use Cell.PutValue("30"), we will treat it as a string value,not int value.

We will try to convert a string value to int value, then to compare it with condition of conditional formats. Thanks for your patience.

Hi Steve,

Please try this fix.

In this fix , we will try to convert the string value to number first before we compare it with condtion.