Jakarta POI 是一套用于访问微软格式文档的Java API。Jakarta POI有很多组件组成,其中有用于操作Excel格式文件的HSSF。使用POI进行Excel表格导入的时候,经常会碰到格式转换的问题。今天在项目中导入Excel表出现了如下错误:
2019-04-24 22:06:06.799 ERROR 7248 --- [io-8082-exec-10] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is java.lang.IllegalStateException: Cannot get a STRING value from a NUMERIC cell] with root cause java.lang.IllegalStateException: Cannot get a STRING value from a NUMERIC cell
一开始将Excel表中的编号设置为String类型,在前端导入Excel表格之后就报上面的错误,于是就把编号更改为Number类型,但是碰到类型转换的的问题,编译器给出了如下的提示:
上网搜了一下,百度知道有小伙伴提供了如下的思路:cell.getNumericCellValue() 返回的是double
Integer.parseInt只能转string
可以强制规定该单元格的格式