How to use NPOI to read Excel spreadsheet that contains empty cells?
How to use NPOI to read Excel spreadsheet that contains empty cells?
Try the GetCell
method with the MissingCellPolicy
:
ICell cell = row.GetCell(2, MissingCellPolicy.RETURN_NULL_AND_BLANK);
https://github.com/tonyqus/npoi/blob/master/main/HSSF/UserModel/HSSFRow.cs#L444
/// <summary> /// Get the hssfcell representing a given column (logical cell) /// 0-based. If you ask for a cell that is not defined then /// you get a null, unless you have set a different /// MissingCellPolicy on the base workbook. /// </summary> /// <param name="cellnum">0 based column number</param> /// <returns>Cell representing that column or null if undefined.</returns> public ICell GetCell(int cellnum) { return GetCell(cellnum, book.MissingCellPolicy); }
https://github.com/tonyqus/npoi/blob/master/main/HSSF/UserModel/HSSFWorkbook.cs#L429
[NonSerialized] private NPOI.SS.UserModel.MissingCellPolicy missingCellPolicy = NPOI.SS.UserModel.MissingCellPolicy.RETURN_NULL_AND_BLANK; /// <summary> /// Retrieves the current policy on what to do when /// getting missing or blank cells from a row. /// The default is to return blank and null cells. /// </summary> /// <value>The missing cell policy.</value> public NPOI.SS.UserModel.MissingCellPolicy MissingCellPolicy { get { return missingCellPolicy; } set { this.missingCellPolicy = value; } }
/// <summary>Missing cells are returned as null, Blank cells are returned as normal</summary> // Token: 0x04001517 RID: 5399 public static readonly MissingCellPolicy RETURN_NULL_AND_BLANK = new MissingCellPolicy(); /// <summary>Missing cells are returned as null, as are blank cells</summary> // Token: 0x04001518 RID: 5400 public static readonly MissingCellPolicy RETURN_BLANK_AS_NULL = new MissingCellPolicy(); /// <summary>A new, blank cell is Created for missing cells. Blank cells are returned as normal</summary> // Token: 0x04001519 RID: 5401 public static readonly MissingCellPolicy CREATE_NULL_AS_BLANK = new MissingCellPolicy();
作者:Chuck Lu GitHub |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
2019-09-29 posh-git
2018-09-29 leelazero and google colab
2018-09-29 download file by python in google colab
2018-09-29 physical processor, core, logical processor
2016-09-29 Entity Framework 不支持DefaultValue
2015-09-29 给枚举加上Description,必要时,可以直接获取枚举类型代表的中文
2015-09-29 word使用技巧