1、错误描述
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 com.you.print.ExcelPrint.readWriteData(ExcelPrint.java:40)
at com.you.print.ExcelPrint.main(ExcelPrint.java:69)
2、错误原因
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 com.you.print.ExcelPrint.readWriteData(ExcelPrint.java:40)
at com.you.print.ExcelPrint.main(ExcelPrint.java:69)
/**
*
*/
package com.you.print;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import jxl.Workbook;
import jxl.format.Border;
import jxl.format.BorderLineStyle;
import jxl.read.biff.BiffException;
import jxl.write.Label;
import jxl.write.WritableCellFormat;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
import jxl.write.WriteException;
import jxl.write.biff.RowsExceededException;
/**
* @author Administrator
*
*/
public class ExcelPrint
{
public void readWriteData()
{
WritableWorkbook wwb = null;
WritableSheet wws=null;
FileOutputStream out =null;
File file = new File("D:\myeclipseworkspces\Print\model\WeightBill.xlsx");
Label label=null;
WritableCellFormat wcf=new WritableCellFormat();
try
{
Workbook wb;
try
{
wb = Workbook.getWorkbook(file);
out = new FileOutputStream(file);
wwb = Workbook.createWorkbook(out, wb);
wws = wwb.getSheet("过磅单");
wcf.setBorder(Border.ALL, BorderLineStyle.THIN);
label = new Label(2, 6, "20170414001", wcf);
wws.addCell(label);
}
catch (BiffException e)
{
e.printStackTrace();
}
catch (IOException e)
{
e.printStackTrace();
}
}
catch (WriteException e)
{
e.printStackTrace();
}
}
/**
* @param args
*/
public static void main(String[] args)
{
new ExcelPrint().readWriteData();
}
}
由于jxl是支持excel2003版本 xsl,不支持excel2007版本 xlsx3、解决办法
(1)修改文件后缀名,改为excel2003版本excel
(2)将jxl有关的jar改为poi jar