我正在尝试从.csv文件中获取单元格数据,但收到错误: jxl.read.biff.BiffException: Unable to recognize stream
我不知道如何解决这个问题,请给我一些解决方案,这段代码是针对jxl的&这个api支持.csv吗?
参考代码:
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();
}
}发布于 2012-09-05 13:01:59
我之前也遇到过这个问题。我在谷歌上搜索并阅读了这篇文章和其他许多寻求这个BiffException解决方案的帖子。我没有确切的解决方案,但当我解决了我的问题时,也许你也可以这样做。
我试图从保存在MS Office2010中的Excel文件中读取数据,但遇到此错误。我将该文件另存为Excel2003-7,然后读取它,没有任何问题。此问题可能出现在Office 10中,但不会出现在Office 2003-7中。
我希望这能在你的情况下起作用。
发布于 2013-10-02 23:46:19
将文件另存为"Excel 97-2003工作簿“类型解决了我的问题。
发布于 2015-02-20 23:17:38
JXL库不支持.csv和.xslx格式,这是Excel-2010使用的格式。因此,请使用.xls格式的Excel97-2003,JXL库支持它。或者,如果您想使用excel-2010,请使用APACHE POI(XSSFWorkbooks)而不是JXL。要使用.csv格式,请使用谷歌的CSVReader库。
https://stackoverflow.com/questions/9799059
复制相似问题