目前使用了POI和JXL的最新版本都不能支持Excel4.0版本的读取。JXL报错信息:
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:221)
at jxl.Workbook.getWorkbook(Workbook.java:198)
at TestJXL.main(TestJXL.java:12)
POI 3.5 beta 6:
java.io.IOException: Invalid header signature; read 0x3209DAC6E6B8A8B1, expected 0xE11AB1A1E011CFD0
at org.apache.poi.poifs.storage.HeaderBlockReader.<init>(HeaderBlockReader.java:120)
at org.apache.poi.poifs.filesystem.POIFSFileSystem.<init>(POIFSFileSystem.java:151)
at TestPOI.main(TestPOI.java:14)
将Excel文件的4.0格式另存为3.0及以下的版本都可以读取。但我的程序是自动读取的,有没有高人可以指点。

解决方案 »

  1.   

     Excel4.0 没用过.等待更新?或者下载源代码下来自己改改.或者等等高人
      

  2.   

    POI(3.0.1版本)还不支持EXCEL4.0以上的版本所造成的,把EXCEL另存为EXCEL3.0或其以下版本就可以解决问题了。 
      

  3.   

    樓主,能不能順便分享一下 java讀取excel的代碼?
      

  4.   

    我这一个上传Excel并读取的Actionimport java.io.File;
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.util.ArrayList;
    import java.util.List;import jxl.Cell;
    import jxl.Sheet;
    import jxl.Workbook;import org.apache.struts2.ServletActionContext;import com.copote.businessManage.common.carManage.bean.CarInfo;
    import com.opensymphony.xwork2.ActionSupport;public class FileUpLoad extends ActionSupport {
    private String title;
    private File upload;
    private String uploadContentType;
    private String uploadFileName; // 接受依赖注入的属性
    private String savePath; // 接受依赖注入的方法
    public void setSavePath(String value) {
    this.savePath = value;
    } private String getSavePath() throws Exception {
    return ServletActionContext.getRequest().getRealPath(savePath);
    } public void setTitle(String title) {
    this.title = title;
    } public void setUpload(File upload) {
    this.upload = upload;
    } public void setUploadContentType(String uploadContentType) {
    this.uploadContentType = uploadContentType;
    } public void setUploadFileName(String uploadFileName) {
    this.uploadFileName = uploadFileName;
    } public String getTitle() {
    return (this.title);
    } public File getUpload() {
    return (this.upload);
    } public String getUploadContentType() {
    return (this.uploadContentType);
    } public String getUploadFileName() {
    return (this.uploadFileName);
    }
    //执行文件上传操作
    @Override
    public String execute() throws Exception {
    System.out.println("开始上传单个文件-----------------------");
    System.out.println(getSavePath());
    System.out.println("==========" + getUploadFileName());
    System.out.println("==========" + getUploadContentType());
    System.out.println("==========" + getUpload());
    // 以服务器的文件保存地址和原文件名建立上传文件输出流
    FileOutputStream fos = new FileOutputStream(getSavePath() + "\\"
    + getUploadFileName());
    FileInputStream fis = new FileInputStream(getUpload());
    byte[] buffer = new byte[1024];
    int len = 0;
    while ((len = fis.read(buffer)) > 0) {
    fos.write(buffer, 0, len);
    }

    //将上传的Excel文件中的数据存储到数据库中
    Workbook workbook = null;
    Sheet sheet = null;
    Cell cell = null;
    System.out.println("读取上传文件");
    try {
    System.out.println("上传文件路径"+getSavePath() + "\\"
    + getUploadFileName());
    workbook = Workbook.getWorkbook(
    new File(getSavePath() + "\\"
    + getUploadFileName()));
    System.out.println("读取文件完毕!");

    } catch (Exception e) {
    System.out.println("无法打开");
    e.printStackTrace();
    }
    try {
    sheet = workbook.getSheet(0);
    } catch (Exception e) {
    System.out.println();
    e.printStackTrace();
    }
    int columnCount = sheet.getColumns();
    int rowCount = sheet.getRows();
    //***********在这里进行数据库操作**************//
    List<CarInfo> carlist= new ArrayList<CarInfo>();
    for (int i = 0; i < rowCount; i++) {
    for (int j = 0; j < columnCount; j++) {
    cell = sheet.getCell(j, i);

    System.out.print(cell.getContents());
    System.out.print("&nbsp;&nbsp;&nbsp;&nbsp;");
    }
    System.out.print("<br>");
    }
    workbook.close();

    return SUCCESS;
    }


    public String input() {
    return "input";
    }
    }
      

  5.   

    我之前用POI 和JXL 的时候都可以
    但是在4.0 没有试过
    你这样呢?先用流读金来,之后什么也不做在output保存的时候再存成低版本,之后再读进数据。你可以试试,不过这样效率上我感觉是个问题,POI读进
    导出
    都OK a搂住 加油啊
      

  6.   

    4.0是什么版本啊我只知道OFFICE07以前的版本和07的存储格式不一样了我最近做的程序,也没办法完全解析07版本的EXCEL,只能得到纯数据,没办法知道其中的格式(即排版)
      

  7.   

    如果是新版的Excel,你就别指望老版本的jxl能读取!