如何使用NPOI读取包含空单元格的Excel电子表格? [英] How to use NPOI to read Excel spreadsheet that contains empty cells?
本文介绍了如何使用NPOI读取包含空单元格的Excel电子表格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我使用NPOI阅读Excel工作表时,将跳过空白单元格.例如,该行包含A, B, , C
,而我使用
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
IRow row = sheet.GetRow(rowNb)
然后row.Cells[1].ToString()
将输出B
(按预期方式),但是row.Cells[2].ToString()
将输出C
而不是空字符串.有没有办法保持空单元格?谢谢.
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.
推荐答案
使用MissingCellPolicy
尝试GetCell
方法:
ICell cell = row.GetCell(2, MissingCellPolicy.RETURN_NULL_AND_BLANK);
这篇关于如何使用NPOI读取包含空单元格的Excel电子表格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文