Search code examples
npoi

Set cell to accept decimal in NPOI library using C#


I am using NPOI to generate an excel spreadsheet for my clients. My exchange rate is in decimal. However, I have to convert it to double because this is what the cellvalue accepts.

            row.CreateCell(17).SetCellValue(Convert.ToDouble(document.ExchangeRate));

I do not want to do this. I want it to accept decimals and not do the conversion as when rounding some data is lost.


Solution

  • The way I overcome this is convert the decimals to String and then the excel representation will be in text.