java 讀取excel 檔案 Unable to recognize OLE stream 錯誤

weixin_34377065發表於2015-01-19

使用 java 程式碼讀取 excel 檔案程式碼時報錯如下:

jxl.read.biff.BiffException: Unable to recognize OLE stream
    at jxl.read.biff.CompoundFile.<init>(CompoundFile.java:116)
    at jxl.read.biff.File.<init>(File.java:127)
    at jxl.Workbook.getWorkbook(Workbook.java:268)
    at jxl.Workbook.getWorkbook(Workbook.java:253)
    at test1.main(test1.java:25)

java 程式碼:

        Workbook wb = null;
        InputStream is = new FileInputStream("e://b2.xlsx");
        try {
            wb = Workbook.getWorkbook(is);
            Sheet rs = wb.getSheet(0);
            int colNum = 11;
            for (int i = 0; i < rs.getRows(); i++) {
                String[] nextLine = new String[colNum];
                for (int j = 0; j < colNum; j++) {
                    nextLine[0] = rs.getCell(j, i).getContents().trim();
                }
            }
        } catch (Exception e) {
            e.printStackTrace();        
        }

原因:不支出讀取 excel 2007 檔案(*.xlsx)。只支援 excel 2003 (*.xls)。

相關文章