从excel获取数据时出错:无效的标头签名

时间:2014-03-06 06:49:14

标签: java excel file exception file-upload

我正在尝试阅读.xlsx Excel文件,但我得到一个例外:

  

从excel获取数据时出错无效的标头签名;读   1688935826934608,预计-2226271756974174256

我错过了什么?

我的代码是

            FileInputStream fileInputStream;
        try {
            fileInputStream = new FileInputStream(filePath + "\\"
                    + "uploadAreaExcel.xlsx");
            HSSFWorkbook workbook;

            workbook = new HSSFWorkbook(fileInputStream);
            HSSFSheet worksheet = workbook.getSheet("Sheet1");

            System.out.println("Total Count :"
                    + Integer.toString(worksheet.getLastRowNum()));
            for(int i=1;i<worksheet.getLastRowNum();i++){
                HSSFRow row1 = worksheet.getRow(i);
                HSSFCell cellA1 = row1.getCell((short) 0);
                System.out.println(cellA1.getStringCellValue());
                HSSFCell cellB1 = row1.getCell((short) 1);
                System.out.println(cellB1.getStringCellValue());
            }
        } catch (Exception e) {
            System.out.println("Error in getting data from excel "+e.getMessage());
        }

1 个答案:

答案 0 :(得分:0)

好的,现在我看到你正在使用HSSF来处理.xlsx文件。但是HSSF不支持.xlsx,你应该尝试XSSF workbook