Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/329.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java没有';无法正确读取excel文件,并且它不会';不能正确识别变量_Java_Excel - Fatal编程技术网

Java没有';无法正确读取excel文件,并且它不会';不能正确识别变量

Java没有';无法正确读取excel文件,并且它不会';不能正确识别变量,java,excel,Java,Excel,我正在用SpringBoot(java)做应用程序,我想阅读excel,但当在excel中显示数据时,年份不正确,excel中的输入“布尔”在java中显示字符串 那一刻,我把这条路变成了铁杆 控制器 @ApiOperation("Upload XLSX file") @RequestMapping(method = RequestMethod.GET, value = "/insert", produces = MediaType.APPLICATION_JSON_VALUE) public

我正在用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;

}
@ApiOperation(“上传XLSX文件”)
@RequestMapping(method=RequestMethod.GET,value=“/insert”,products=MediaType.APPLICATION\u JSON\u value)
公共MyMessage创建(@RequestBody MultipartFile multipart){
试一试{
InputStream multipartFile=新文件InputStream(“C:\\Users\\emartinp\\Desktop\\Nominacion.xlsx”);
工作簿wb=WorkbookFactory.create(多部分文件);
Sheet Sheet=wb.getSheetAt(0);
页眉=sheet.getHeader();
int rowsunt=sheet.getLastRowNum();
System.out.println(“总行数:”+(rowsCount+1));

对于(int i=0;i对于
-1
部分,工作表被认为有20行,只填充了3行,因此其他17个空行的列计数为-1。还要重新检查文件中的数据,或者创建一个新的数据并重新测试。数据不正确吗?对于数据,这就是我建议重新检查文件内容或创建一个新的,1905不可能转换一次到1995年,一次到2003年。很可能你处理的是错误的文件。该文件没有错误,因为我可以读取“edou”edou4“chemita”等。如果我输入excell所有输入格式“text”,Java可以正确读取。