我试图将我的 Java 程序与 Excel 文件连接起来。我已经做到了这一点。但是它抛出了这个异常
Unable to recognize OLE stream
请帮我完成这个。
import jxl.*;
import java.io.*;
public class excel
{
public static void main(String[] args)throws Exception
{
File ex=new File("D:/worksps/test.xlsx");
Workbook w= Workbook.getWorkbook(ex);
Sheet s= w.getSheet(0);
for(int i=0;i<s.getColumns();i++)
{
for(int j=0;j<s.getRows();j++)
{
Cell cell=s.getCell(i, j);
System.out.println(" "+cell.getContents());
}
System.out.println("\n");
}
}
}
最佳答案
JXL 支持在 Excel 95/97 和 2000 中创建的 Excel 工作表 -
阅读 JXL 官方网站中的以下内容 - http://www.andykhan.com/jexcelapi/
Features
Reads data from Excel 95, 97, 2000 workbooks Reads and writes formulas (Excel 97 and later only) Generates spreadsheets in Excel 2000 format
您的 excel 表似乎是在 Excel 2000 之后创建的。这似乎是问题所在。
如果您想读取 Excel 2000 之后创建的 Excel 文件,那么您应该使用 Apache POI。它也是一个易于使用的 API,支持 MS Excel 97 到 MS Excel 2008。
关于java - 连接到 Excel 时出现 "Unable to recognize OLE stream"异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5497681/