如何在NPOI中设置数值型空单元格

我使用NPOI来创build一个excel文件。 如果单元格是数字,则编写单元格的代码是

row.CreateCell(j).SetCellValue(Runtime); 

因为只有一个函数来设置单元格的值。 但是,如果运行时缺失,并使用SetCellValue(“”),那么单元格types是string,不再是数字。 阅读时

 GetCell(cell, MissingCellPolicy.CREATE_NULL_AS_BLANK).NumericCellValue 

它会返回一个exception:

 "Can not get numerical value from text cell." 

那么如何在这种情况下编写单元? 谢谢。

尝试使用

 cell.SetCellType( CellType.Numeric); 

在分配之前