【Java-jxl插件】【Excel文件读写报错】jxl.read.biff.BiffException: Unable to recognize OLE stream

问题:

使用了两种方式读取excel,执行都报错:jxl.read.biff.BiffException: Unable to recognize OLE stream

以下代码片段:

package com.hlq.atm.excelCase;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;

public class ExcelReadWrite {

    public static void main(String[] args) {
        ExcelReadWrite erw=new ExcelReadWrite();
        String path=System.getProperty("user.dir");
//        erw.readExcelByJxl(path+"/data/Students.xls");
        erw.re(path+"/data/Students.xls");
    }

    public void re(String pathName) {
        try {
            //创建workbook
            Workbook workbook=Workbook.getWorkbook(new File(pathName));
            //获取第一个工作表sheet
            Sheet sheet=workbook.getSheet(0);
            //获取数据
            for (int i=0;i 
  
    public void readExcelByJxl(String fileName) {
File file=new File(fileName);
try {
// FileInputStream fis=new FileInputStream(file);
Workbook workbook=Workbook.getWorkbook(file);
Sheet[] sheet=workbook.getSheets();
for (int i=0;i Sheet rs=workbook.getSheet(i);
//遍历行
for (int j=0;j Cell[] cells=rs.getRow(j);
//遍历列
for (int z=0;z System.out.print(cells[z].getContents());
System.out.print("\t");
}
System.out.println();
}
}
workbook.close();

} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (BiffException e) {
e.printStackTrace();
}
}
}

 

原因:

在网上查询改报错原因,是文件版本不兼容,jxl只支持excecl03版

 

解决办法:

尝试另存文件,选择Excel 97-2004工作簿,再次执行,执行通过

【Java-jxl插件】【Excel文件读写报错】jxl.read.biff.BiffException: Unable to recognize OLE stream_第1张图片

执行结果:

【Java-jxl插件】【Excel文件读写报错】jxl.read.biff.BiffException: Unable to recognize OLE stream_第2张图片

 

你可能感兴趣的:(【Java-jxl插件】【Excel文件读写报错】jxl.read.biff.BiffException: Unable to recognize OLE stream)