Problem with cells formating


for some reason following code does not change the color of the font for negative/positive numbers.
cells contain the data in the format like "123,456"
is there something wrong with the way I do it?
is there a better way to do it?

in general, what format do the cells have, when the worksheet is just created? Text?

private void download(string type)
TopHolderService topHolderService = new TopHolderService();
DataView dv = topHolderService.GetTopHolders(TextBox1.Text, int.Parse(DropDownList1.SelectedValue),“I”,0);
if (dv == null) return;
Excel excel = new Excel();
Worksheet sheet = excel.Worksheets[0];
int count;
if (count <=0)

int i;

int styleIndex = excel.Styles.Add();
int styleIndex2 = excel.Styles.Add();
Aspose.Excel.Style stylePositive ,styleNegative;
stylePositive = excel.Styles[styleIndex];
styleNegative= excel.Styles[styleIndex2];
stylePositive.Font.Color = Color.Green;
styleNegative.Font.Color = Color.Red;
try {
if (double.Parse(sheet.Cells[i,6].ToString(),System.Globalization.NumberStyles.AllowThousands)>0)
sheet.Cells[i,6].Style = stylePositive;
else if(double.Parse(sheet.Cells[i,6].ToString(),System.Globalization.NumberStyles.AllowThousands)<0)
sheet.Cells[i,6].Style = styleNegative;
catch (Exception e)
// if something wrong, don’t format the number



This problem is caused by that Cell.ToString() always returns “Aspose.Excel.Cell”.

So please change your code to:

Cell cell = sheet.Cells[i,6];
case CellValueType.IsNumeric:
if(cell.DoubleValue > 0)
cell.Style = stylePostive;
else if(cell.DoubleValue < 0)
cell.Style = styleNegative;