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条回答
Rolldiameter
2楼-- · 2019-02-16 10:58

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.

查看更多
够拽才男人
3楼-- · 2019-02-16 11:06

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.

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.

I hope this will work in your case.

查看更多
登录 后发表回答