"Unable to recognize OLE stream" excepion while connecting to Excel

V I J E S H picture V I J E S H · Mar 31, 2011 · Viewed 59.8k times · Source

I was trying to connect my Java program with an Excel file. I have did upto this. But it throws this excepion

Unable to recognize OLE stream

Please, help me to complete this.

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

Answer

Pushkar picture Pushkar · Mar 31, 2011

JXL supports Excel worksheets created in Excecl 95/97 and 2000 -

Read the below in the official JXL site - 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

Your excel sheet seems to be created after Excel 2000. That seems to be the problem.

If you want to read Excel files created after Excel 2000 then you should use Apache POI. It is also an easy to use API and supports MS Excel 97 to MS Excel 2008.