When I read Excel worksheet using NPOI, empty cells are skipped. For example, it the row contains A, B, , C
and I read it using
当我使用NPOI阅读Excel工作表时,会跳过空单元格。例如,它的行包含A、B、C和我读它使用。
IRow row = sheet.GetRow(rowNb)
then row.Cells[1].ToString()
will output B
(as expected) but row.Cells[2].ToString()
will output C
instead of an empty string. Is there a way to keep empty cells? Thanks.
然后row.Cells[1]. tostring()将输出B(如预期),而row.Cells[2]. tostring()将输出C而不是空字符串。是否有办法保持空单元格?谢谢。
1 个解决方案
#1
16
Try the GetCell
method with the MissingCellPolicy
:
使用MissingCellPolicy尝试GetCell方法:
ICell cell = row.GetCell(2, MissingCellPolicy.RETURN_NULL_AND_BLANK);
#1
16
Try the GetCell
method with the MissingCellPolicy
:
使用MissingCellPolicy尝试GetCell方法:
ICell cell = row.GetCell(2, MissingCellPolicy.RETURN_NULL_AND_BLANK);