博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
poi--读取不同类型的excel表格
阅读量:4617 次
发布时间:2019-06-09

本文共 2153 字,大约阅读时间需要 7 分钟。

要想根据不同类型excel表格获取其数据,就要先判断其表格类型

poi-api种方法:

getCellType

    public int getCellType()
        Return the cell type.

Specified by:

     getCellType in interface Cell
Returns:
     the cell type
See Also:
Cell.CELL_TYPE_BLANK, Cell.CELL_TYPE_NUMERIC, Cell.CELL_TYPE_STRING, Cell.CELL_TYPE_FORMULA, Cell.CELL_TYPE_BOOLEAN, Cell.CELL_TYPE_ERROR

--------------------------------------------------------------------------------
CELL_TYPE_NUMERIC        double
static final int CELL_TYPE_NUMERICNumeric Cell type (0)
--------------------------------------------------------------------------------
CELL_TYPE_STRING        String
static final int CELL_TYPE_STRINGString Cell type (1)
--------------------------------------------------------------------------------
CELL_TYPE_FORMULA        带excel函数
static final int CELL_TYPE_FORMULAFormula Cell type (2)
--------------------------------------------------------------------------------
CELL_TYPE_BLANK
static final int CELL_TYPE_BLANKBlank Cell type (3)
--------------------------------------------------------------------------------
CELL_TYPE_BOOLEAN        Boolean
static final int CELL_TYPE_BOOLEANBoolean Cell type (4)
--------------------------------------------------------------------------------
CELL_TYPE_ERROR
static final int CELL_TYPE_ERRORError Cell type (5)
--------------------------------------------------------------------------------
例子:
XSSFCell xssfcell = (XSSFCell) row.getCell(0);      switch(xssfcell.getCellType()){        case NUMERIC://double            double val1 = xssfcell.getNumericCellValue();            break;        case STRING://String            String val2 = xssfcell.getStringCellValue();            break;        case FORMULA://表格内容是通过excel函数得到            XSSFRichTextString val3 = xssfcell.getRichStringCellValue();            String val4 = String.valueOf(val3);            break;        case BLANK://空白表格            break;        case BOOLEAN://boolean            boolean val6 = xssfcell.getBooleanCellValue();            break;        case ERROR://错误单元格            String val7 = xssfcell.getErrorCellString();            break;        default:            break;     }

 

转载于:https://www.cnblogs.com/it-mh/p/10550426.html

你可能感兴趣的文章
Linux搭建Nexus3.X构建maven私服
查看>>
Notepad++使用NppFTP插件编辑linux上的文件
查看>>
NPOI 操作Excel
查看>>
MySql【Error笔记】
查看>>
vue入门
查看>>
JS线程Web worker
查看>>
Flex的动画效果与变换!(三)(完)
查看>>
mysql常见错误码
查看>>
Openresty 与 Tengine
查看>>
使用XV-11激光雷达做hector_slam
查看>>
布局技巧4:使用ViewStub
查看>>
ddt Ui 案例2
查看>>
拿下主机后内网的信息收集
查看>>
LeetCode 876. Middle of the Linked List
查看>>
作业一
查看>>
joj1023
查看>>
动画原理——旋转
查看>>
Finding LCM LightOJ - 1215 (水题)
查看>>
python生成器
查看>>
PowerDesigner Constraint name uniqueness 错误
查看>>