使用POI读取excel文件内容
?
3.总结
因为excel单元格中的内容往往都有一定的格式,比如日期型,数字型,字符串型,因此在读取的时候要进行格式判断,不然会出现错误。常见的就是不能正常读取日期。在代码实例中有一个方法:
getCellFormatValue(HSSFCell cell)
往这个方法中传入excel单元格就能识别单元格格式,并转化为正确的格式。
ps:2012-2-23
代码实例中有一段代码:
int colNum = row.getPhysicalNumberOfCells();
?其中的HSSFRow.getPhysicalNumberOfCells();这个方法是用于获取一行中存在的单元格数,POI的官方API中有给出getPhysicalNumberOfCells方法的解释
getPhysicalNumberOfCellspublic int getPhysicalNumberOfCells()
gets the number of defined cells (NOT number of cells in the actual row!).?That is to say if only columns 0,4,5 have values then there would be 3. Specified by: getPhysicalNumberOfCells?in interface?RowReturns: int representing the number of defined cells in the row.作者:xwdreamer出处:http://www.cnblogs.com/xwdreamer?
getPhysicalNumberOfCells?in interface?Row