这里我想通过使用下面的java代码来读取xl表单,但是我在阅读单元格时遇到了异常,如下所示。使用java代码读取xl sheeet
XL读码
Cell cell14 = row.getCell(14);
int celltype = cell4.getCellType();
if (celltype == HSSFCell.CELL_TYPE_BOOLEAN) {
System.out.println("inide boolean");
row.getCell(14).getBooleanCellValue();
System.out.println("row.getCell(14).getBooleanCellValue()" + row.getCell(14).getBooleanCellValue());
} else if (celltype == HSSFCell.CELL_TYPE_ERROR) {
System.out.println("inide CELL_TYPE_ERROR");
row.getCell(14).getErrorCellValue();
System.out.println("row.getCell(14).getErrorCellValue()" + row.getCell(14).getErrorCellValue());
} else if (celltype == HSSFCell.CELL_TYPE_FORMULA) {
System.out.println("inide CELL_TYPE_FORMULA");
row.getCell(14).getCellFormula();
System.out.println(" row.getCell(14).getCellFormula()" + row.getCell(14).getCellFormula());
} else if (celltype == HSSFCell.CELL_TYPE_NUMERIC) {
System.out.println("inide CELL_TYPE_NUMERIC");
row.getCell(14).getNumericCellValue();
System.out.println("row.getCell(14).getNumericCellValue()" + row.getCell(14).getNumericCellValue());
} else if (celltype == HSSFCell.CELL_TYPE_STRING) {
System.out.println("inide CELL_TYPE_STRING");
row.getCell(14).getRichStringCellValue();
System.out.println("row.getCell(14).getStringCellValue();" + row.getCell(14).getRichStringCellValue());
}
这里是例外
java.lang.IllegalStateException: Cannot get a text value from a numeric cell
at org.apache.poi.hssf.usermodel.HSSFCell.typeMismatch(HSSFCell.java:643)
at org.apache.poi.hssf.usermodel.HSSFCell.getRichStringCellValue(HSSFCell.java:720)
at org.apache.poi.hssf.usermodel.HSSFCell.getRichStringCellValue(HSSFCell.java:67)
我的电话号码有在XL是这样975125351237但里面numaric正在读这样9.788184771442E12 u能PLZ解决这个问题 – user3214269
这听起来像是一个不同的问题。 xls文件中是否有类似的值? –
@ user3214269格式化问题我同意这是一个不同的问题,也许参考此解决方案http://stackoverflow.com/questions/21624528/how-to-read-exact-cell-content-of-excel-file-in- apache-poi/21625090#21625090 – PopoFibo