how to solve JXL error : jxl.read.biff.BiffExcepti

2019-02-16 09:59发布

i am trying to get cell data from my .csv file but it gets error : jxl.read.biff.BiffException: Unable to recognize OLE stream

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?

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();
    }

}

8条回答
仙女界的扛把子
2楼-- · 2019-02-16 10:40

save the file as Excel 97-2003 and also change the file format from xlsx to xlx , in the code(in the file name)

查看更多
Animai°情兽
3楼-- · 2019-02-16 10:42

Save the Excel file type as Excel 97-2003 Worksheet and extension type as xls

查看更多
手持菜刀,她持情操
4楼-- · 2019-02-16 10:46

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

查看更多
别忘想泡老子
5楼-- · 2019-02-16 10:47

Saving File as "Excel 97-2003 Workbook" type solved my issue.

查看更多
你好瞎i
6楼-- · 2019-02-16 10:51

Actually you are using different version of csv file .Please save it in the exact version.

For ex: we should save the excel sheet in word as 9

查看更多
唯我独甜
7楼-- · 2019-02-16 10:53

JXL is a simple (and hence limited) API. If it says

Unable to recognize OLE stream

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.

  • 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.

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.

查看更多
登录 后发表回答