Error displayed with green color (6.0 KB)
I am facing weird issue. I have currency values to display in Excel. I am getting value as text from third party application and I am printing those values in excel as it is.
After that I convert that to Custom format giving Currency format string displayed below.

Problem is I am getting all values shown as custom but I am unable to perform any calculation on them. Looks like it is still text. Also when I F2 on particular cell and do nothing just press enter it comes up perfectly fine.

Attached is the file which is generated with my code.


string sFormat = “$#,##0.00;-$#,##0.00”;
Aspose.Cells.Range oRange = _oSheetCollection[sSheetName].Cells.CreateRange(oXlsRange.FirstRow, oXlsRange.FirstColumn, oXlsRange.RowNum, oXlsRange.ColNum);

        Aspose.Cells.Style oStyle = _oSheetCollection[sSheetName].Cells[oXlsRange.FirstRow, oXlsRange.FirstColumn].GetStyle();
        oStyle.Custom = sFormat;
        Aspose.Cells.StyleFlag flag = new Aspose.Cells.StyleFlag();
        flag.All = true;

        oRange.ApplyStyle(oStyle, flag);

Please help.



Thanks for the template file and sample code.

Well, your so called numeric data is string (you will see green triangle saying “Number stored as text” on top left corner of the cell(s)). If you want values to display proper formats and you could perform calculations, you need to convert those string values(in the cells) to numeric values. Otherwise you will not be able to set your desired tasks.

Alternatively, you may use overloaded version of the method, e.g Cell.PutValue(string stringvalue, bool isConverted) to convert each cells’ existing value (if possible) to numeric values, set the last argument to true. I think you may loop through all the cells and use this overloaded version of the method to convert every possible string value to numeric value (if possible) for the same cell.
Sample code:

      cell.PutValue(cell.StringValue, true);

Hope, this helps a bit.