当前位置: 移动技术网 > IT编程>开发语言>.net > NPOI 笔记

NPOI 笔记

2018年02月09日  | 移动技术网IT编程  | 我要评论

易虎臣女友叶雪,明史十讲,毕娇

前言

文档:

示例:https://npoi.svn.codeplex.com/svn/

版本:2.2.1 (通过nuget进行安装的)

 应用场景:https://github.com/zhaoqingqing/TableML  解析Excel数据成tsv(类似csv)

基础知识

workbook(工作薄):一个excel文件可以包含多张表(sheet)

行:Row

列:Column

单元格:Cell

 

 

NPOI Cannot get a text value from a numeric formula cell

当单元格的内容是由公式组成时,获取值时报以下Error:

未经处理的异常:  System.InvalidOperationException: Cannot get a text value from a numeric formula cell
   在 NPOI.XSSF.UserModel.XSSFCell.get_RichStringCellValue()
   在 NPOI.XSSF.UserModel.XSSFCell.get_StringCellValue()

解决方法:

通过上面的调试信息可以看到 cell.CachedFormulaResultType 有表示这个公式单元格的类型

switch (cell.CachedFormulaResultType)
{
    //已测试:SUM,& 
        case CellType.Numeric:
            return cell.NumericCellValue.ToString();
        case  CellType.String:
            return cell.StringCellValue;
}

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网