Java 如何解决 JXL 错误:jxl.read.biff.BiffException:无法识别 OLE 流
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9799059/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how to solve JXL error : jxl.read.biff.BiffException: Unable to recognize OLE stream
提问by user1263633
i am trying to get cell data from my .csv file but it gets error : jxl.read.biff.BiffException: Unable to recognize OLE stream
我正在尝试从我的 .csv 文件中获取单元格数据,但出现错误:jxl.read.biff.BiffException:无法识别 OLE 流
I don't understand how to solve this,please give me some solution this code is for jxl api & is that api support to .csv?
我不明白如何解决这个问题,请给我一些解决方案,此代码适用于 jxl api &该 api 支持 .csv 吗?
Code for reference:
参考代码:
public void read() throws IOException, BiffException {
File inputWorkbook = new File(inputFile);
try
{
w = Workbook.getWorkbook(inputWorkbook.getAbsoluteFile());
// Get the first sheet
Sheet sheet = w.getSheet(0);
// Loop over first 10 column and lines
for (row = 1; row < sheet.getRows(); row++)
{
ReadExcelLotSizeEntity readExcelLotSizeEntity =new ReadExcelLotSizeEntity();
cell = sheet.getCell(1,row);
type= cell.getType();
if (cell.getType() == CellType.LABEL)
{
symbol=cell.getContents();
System.out.println(":::::::::::::::::"+symbol);
readExcelLotSizeEntity.setSymbol(symbol);
}
int col=2;
cell = sheet.getCell(col,row);
while(!cell.getContents().equals("")||cell.getContents()!=null)
{
System.out.println("||||||||||||||||"+cell.getContents());
cell=sheet.getCell(col,row);
col++;
}
lotSize= new Double(cell.getContents());
readExcelLotSizeEntity.setLotSize(lotSize);
readExcelLotSizeEntity.setCreateUserId(1L);
readExcelLotSizeEntity.setCreateDtTm(new Date());
readExcelLotSizeHome.persist(readExcelLotSizeEntity);
}
} catch (BiffException e) {
e.printStackTrace();
}
}
回答by user1251551
Actually you are using different version of csv file .Please save it in the exact version.
实际上您使用的是不同版本的 csv 文件。请将其保存在确切版本中。
For ex: we should save the excel sheet in word as 9
例如:我们应该将word中的excel表保存为9
回答by Vinod Kumar Chauhan
I was also facing this problem earlier. I googled and read this post and many other posts that were asking for solution to this BiffException
. I don't have the exact solution but as I fixed my problem you can do it too, perhaps.
我之前也遇到过这个问题。我在谷歌上搜索并阅读了这篇文章和许多其他寻求解决方案的文章BiffException
。我没有确切的解决方案,但是当我解决了我的问题时,您也许也可以这样做。
I was trying to read data from the Excel file saved in MS Office 2010and I was getting this error. I saved the file as an Excel 2003-7and then read it without any problem. It may the case that this problem occurs in Office 10but not in Office 2003-7.
我试图从保存在MS Office 2010 中的 Excel 文件中读取数据,但出现此错误。我将文件另存为Excel 2003-7,然后毫无问题地读取它。此问题可能会出现在Office 10 中,但不会出现在Office 2003-7 中。
I hope this will work in your case.
我希望这对你的情况有效。
回答by user2839342
Saving File as "Excel 97-2003 Workbook" type solved my issue.
将文件另存为“Excel 97-2003 工作簿”类型解决了我的问题。
回答by Sreekanth
save the file as Excel 97-2003 and also change the file format from xlsx to xlx , in the code(in the file name)
将文件另存为 Excel 97-2003 并将文件格式从 xlsx 更改为 xlx ,在代码中(在文件名中)
回答by prasad vsv
JXL library doesnot support .csv
and .xslx
formats, which is the format used by Excel-2010. hence, use Excel 97-2003 which is .xls
foramatted and is supported by JXL library.
or else if you want to use excel-2010, use APACHE POI(XSSFWorkbooks) instead of JXL.
For using .csv format, google for CSVReader libraries.
JXL 库不支持 .csv
和.xslx
格式,这是 Excel-2010 使用的格式。因此,请使用.xls
格式化并受 JXL 库支持的Excel 97-2003 。否则,如果您想使用 excel-2010,请使用 APACHE POI(XSSFWorkbooks) 而不是 JXL。要使用 .csv 格式,请谷歌搜索 CSVReader 库。
回答by Kishor Ambare
I was trying to read data from the Excel file saved in MS Office 2010 and I was getting this error. I saved the file as an Excel 2003-7 and then read it without any problem. It may the case that this problem occurs in Office 10 but not in Office 2003-7
我试图从保存在 MS Office 2010 中的 Excel 文件中读取数据,但出现此错误。我将文件另存为 Excel 2003-7,然后毫无问题地读取它。可能是这个问题出现在 Office 10 而不是 Office 2003-7
回答by Prashant1992
Save the Excel file type as Excel 97-2003 Worksheet and extension type as xls
将 Excel 文件类型另存为 Excel 97-2003 工作表,将扩展名类型另存为 xls
回答by VHS
JXLis a simple (and hence limited) API. If it says
JXL是一个简单(因此有限)的 API。如果它说
Unable to recognize OLE stream
无法识别 OLE 流
it is what it is. It doesn't quite understand your Excel XLS file. Have confidence that the error is legitimate. This API only supports *.xls
files; it doesn't support, for example, *.csv
or *.xlsx
files. Obviously, having the file renamed to *.xls
alone is not sufficient. It must be in Excel 97-2003 format too.
就是这样。它不太了解您的 Excel XLS 文件。确信错误是合法的。此 API 仅支持*.xls
文件;例如,它不支持*.csv
或*.xlsx
文件。显然,将文件重命名为*.xls
单独是不够的。它也必须是 Excel 97-2003 格式。
- Copy all the cells from your
*.csv
or*.xlsx
file. - Open MS Excel and paste the copied cells.
- Save the file as MS Excel 97-2003 (
*.xls
) file.
- 复制您
*.csv
或*.xlsx
文件中的所有单元格。 - 打开 MS Excel 并粘贴复制的单元格。
- 将文件另存为 MS Excel 97-2003 (
*.xls
) 文件。
This error will surely not appear again.
这个错误肯定不会再出现了。
On the other hand, if you want to process other formats (xlsx, csv) directly, look for other tools like Apache POI.
另一方面,如果您想直接处理其他格式(xlsx、csv),请寻找其他工具,例如 Apache POI。