NPOI 空单元格的获取

 

 

IRow row = sheet.GetRow(i);

坑:如果此行存在空的cell,则row.Cells[index] 不能获取到,空的单元格不能生成cells 

 

        /// <summary>
        /// 获取这一列的某个Cell
        /// </summary>
        /// <param name="Row"></param>
        /// <param name="index"></param>
        /// <returns></returns>
        public ICell GetCell(IRow Row, int index)
        {
            ICell cell = Row.FirstOrDefault(n => n.ColumnIndex == index);
            if (cell == null)
            {
                cell = Row.CreateCell(index);
            } 
            return cell;
        }

  

posted @ 2018-10-31 17:00  人生为卒  阅读(1121)  评论(0编辑  收藏  举报