How to use NPOI to read Excel spreadsheet that contains empty cells?

孤人 提交于 2019-12-18 14:17:34

问题


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)

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.


回答1:


Try the GetCell method with the MissingCellPolicy:

ICell cell = row.GetCell(2, MissingCellPolicy.RETURN_NULL_AND_BLANK);


来源:https://stackoverflow.com/questions/17475359/how-to-use-npoi-to-read-excel-spreadsheet-that-contains-empty-cells

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!