Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

java

excel

ole

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");
       }
      }
}
like image 698
V I J E S H Avatar asked Mar 31 '11 09:03

V I J E S H


People also ask

What is Ole stream?

An OLE file can be seen as a mini file system or a Zip archive: It contains streams of data that look like files embedded within the OLE file. Each stream has a name. For example, the main stream of a MS Word document containing its text is named “WordDocument”. An OLE file can also contain storages.


1 Answers

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.

like image 129
Pushkar Avatar answered Sep 28 '22 01:09

Pushkar