This project has moved. For the latest updates, please go here.

Creating number cell

Sep 27, 2012 at 8:17 AM

Hello,

I am creating excel using EPPLUS. When number is stored in cell, I am getting a message “The number in this cell is formatted as text or preceded by an apostrophe”. How can trun off this message and convert the cell as number cell.

Thanks in advance.

Thanks,

Ram

Sep 27, 2012 at 5:25 PM

I  am not sure of your specific situation without seeing the code that you are using.  I am pretty sure that it depends on the data type of the variable on the right side of the assignment statement as the Value property is an object.  So, make sure that you cast your variable to be how you want excel to hold it and then use the column formatting to change the display.  For example, if a cell should be treated as a money field, then I would use the following.

ExcelWorksheet tab = [Assign this to your worksheet that has the data on it];

decimal cellAmount;
string amount="50.35";

if(decimail.TryParse(amount, out cellAmount)){
    tab.Cells[1,1].Value=cellAmount;
    tab.Cells[1, 1].Style.Numberformat ="$#,##0.00";
}