java - Java 无法正确读取 excel 文件并且无法正确识别 vars
问题描述
我正在使用SpringBoot(java)做应用程序,我想读取excel,但是当显示excel数据时,年份不正确,并且excel中的输入“布尔”显示java中的字符串。
那一刻我把路径铁杆。
控制器
@ApiOperation("Upload XLSX file")
@RequestMapping(method = RequestMethod.GET, value = "/insert", produces = MediaType.APPLICATION_JSON_VALUE)
public MyMessage create(@RequestBody MultipartFile multipart) {
try {
InputStream multipartFile = new FileInputStream("C:\\Users\\emartinp\\Desktop\\Nominacion.xlsx");
Workbook wb = WorkbookFactory.create(multipartFile);
Sheet sheet = wb.getSheetAt(0);
Header header = sheet.getHeader();
int rowsCount = sheet.getLastRowNum();
System.out.println("Total Number of Rows: " + (rowsCount + 1));
for (int i = 0; i <= rowsCount; i++) {
Row row = sheet.getRow(i);
int colCounts = row.getLastCellNum();
System.out.println("Total Number of Cols: " + colCounts);
for (int j = 0; j < colCounts; j++) {
Cell cell = row.getCell(j);
switch (cell.getCellType()) {
case Cell.CELL_TYPE_NUMERIC:
System.out.println("es num" + cell.getNumericCellValue());
break;
case Cell.CELL_TYPE_STRING:
System.out.println("es string" + cell.getStringCellValue());
break;
case Cell.CELL_TYPE_BOOLEAN:
System.out.println("boolean" + cell.getBooleanCellValue());
break;
}
// System.out.println("[" + i + "," + j + "]=" + cell.getStringCellValue());
}
}
} catch (Exception ex) {
System.out.println("Error " + ex);
} finally {
}
return null;
}
结果
可以看到java中excell中的boolean类型是String类型... 那么year
"1905" Java read是2003.0
Month
01 Java read 2.0
Boolean
false in Excel中Java read String。
最后spam -1
...
解决方案
推荐阅读
- c++ - 模板数组句柄库中的内存泄漏
- python - 如何将 2 个现有条形图变成一个子图
- kubernetes - 在 Kubernetes 集群的特定节点上安装 Kubeflow
- okta - FreeRadius:到 PAP Radius 服务器的 EAP-PEAP 代理?
- javascript - 脚本标签中的 Kaltura 缩略图视频在反应中不起作用但显示空白
- javascript - Javascript html如何获取输入类型按钮的值
- react-native - 如何在 React Native 中直接打开应用的位置权限设置
- sql - 如何将数据列转换为单列,其中每一行数据都垂直堆叠在该列中(在 Postgres 中)?
- regex - vscode 正则表达式的奇怪问题 - vscode 不匹配简单字母?
- android - 在 Android 11 中无法使用 taskAffinity 进行跨应用程序活动