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

Posted 咕噜噜的肥猫

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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<sheet.getRows();i++){
                for (int j=0;j<sheet.getColumns();j++){
                    Cell cell=sheet.getCell(j,i);
                    System.out.print(cell.getContents()+" ");
                }
                System.out.println();
            }

            workbook.close();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (BiffException e) {
            e.printStackTrace();
        }
    }
    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.length;i++){
Sheet rs=workbook.getSheet(i);
//遍历行
for (int j=0;j<rs.getRows();j++){
Cell[] cells=rs.getRow(j);
//遍历列
for (int z=0;z<cells.length;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的主要内容,如果未能解决你的问题,请参考以下文章

JXL读写Excel表格数据

导出excel报错:java.lang.ClassNotFoundException: jxl.format.CellFormat

使用jxl操作之一: 实现对Excel简单读写操作

POI读写海量Excel

如何从java输出到excel

java大概1000W数据导出成excel有啥好的建议。(最好是插件,POI、JXL、FastExcel已试过,数据量太大,不