Results 1 to 7 of 7
  1. #1
    Subhransu is offline Member
    Join Date
    Feb 2011
    Posts
    7
    Rep Power
    0

    Default Excel File Reader

    Hi,

    I have to read an excel file, get the data and put it into the database.
    But I am getting the below error.

    jxl.read.biff.BiffException: Unable to recognize OLE stream
    at jxl.read.biff.CompoundFile.<init>(CompoundFile.jav a:116)
    at jxl.read.biff.File.<init>(File.java:127)
    at jxl.Workbook.getWorkbook(Workbook.java:221)
    at jxl.Workbook.getWorkbook(Workbook.java:198)...

  2. #2
    j2me64's Avatar
    j2me64 is offline Senior Member
    Join Date
    Sep 2009
    Location
    Zurich, Switzerland
    Posts
    962
    Rep Power
    6

    Default

    can you please post the lines of code you use to read the excel file?

  3. #3
    Subhransu is offline Member
    Join Date
    Feb 2011
    Posts
    7
    Rep Power
    0

    Default

    Java Code:
    import java.io.File;
    import java.io.*;
    import jxl.*;
    import java.util.*;
    import jxl.Workbook;
    import jxl.read.biff.*;
    
    class readXls {
    	public static void main(String[] args) {
    		try {
    			String filename = "D:/StockDataMigration/StockData/test/UAECONTACTS.xlsx";
    			WorkbookSettings ws = new WorkbookSettings();
    			ws.setLocale(new Locale("en", "EN"));
    
    			Workbook workbook = Workbook.getWorkbook(new File(filename), ws);
    
    			Sheet s = workbook.getSheet(0);
    			Sheet s1 = workbook.getSheet(1);
    			readDataSheet(s1);
    			readImageSheet(s);
    			workbook.close();
    		} catch (IOException e) {
    			e.printStackTrace();
    		} catch (BiffException e) {
    			e.printStackTrace();
    		}
    
    	}
    
    	private static void readDataSheet(Sheet s) {
    		// Find the labeled cell from sheet
    		LabelCell lc = s.findLabelCell("Date");
    		System.out.println(lc.getString());
    
    		// gets the value of cell at specified column and row
    		DateCell dc = (DateCell) s.getCell(0, 1);
    		System.out.println(dc.getDate());
    
    		lc = s.findLabelCell("Add 2 cells");
    		System.out.println(lc.getString());
    
    		NumberCell c = (NumberCell) s.getCell(4, 1);
    		System.out.println(c.getValue());
    
    		c = (NumberCell) s.getCell(4, 2);
    		System.out.println(c.getValue());
    
    		NumberFormulaCell nc = (NumberFormulaCell) s.getCell(4, 3);
    		System.out.println(nc.getValue());
    
    	}
    
    	private static void readImageSheet(Sheet s) {
    		LabelCell lc = s.findLabelCell("Image");
    		System.out.println(lc.getString());
    
    		// Gets the image stored in excel document
    		Image c = s.getDrawing(0);
    		System.out.println(c.getImageFile());
    
    	}
    }
    Last edited by Eranga; 03-02-2011 at 09:29 AM. Reason: added code tags

  4. #4
    j2me64's Avatar
    j2me64 is offline Senior Member
    Join Date
    Sep 2009
    Location
    Zurich, Switzerland
    Posts
    962
    Rep Power
    6

    Default

    the jxl.jar does not support xlsx files. try poi to read xlsx-files, you can get it from Apache POI - the Java API for Microsoft Documents

  5. #5
    Subhransu is offline Member
    Join Date
    Feb 2011
    Posts
    7
    Rep Power
    0

    Default

    Does the jxl jar supports .xls file ?

  6. #6
    j2me64's Avatar
    j2me64 is offline Senior Member
    Join Date
    Sep 2009
    Location
    Zurich, Switzerland
    Posts
    962
    Rep Power
    6

    Default

    Quote Originally Posted by Subhransu View Post
    Does the jxl jar supports .xls file ?

    yes. this is also a workaround, try to save your excel sheet as a xls instead of a xlsx.

  7. #7
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    @OP, just to update. Please use [ and ] tags when you are posting code segments through the Quick Reply window. Or else use tags adding option in Advance Replay.

    Thanks you!

Similar Threads

  1. problem with file reader
    By Stormrage in forum New To Java
    Replies: 7
    Last Post: 05-15-2010, 11:48 PM
  2. Selecting an input file for Reader
    By myazuid in forum New To Java
    Replies: 3
    Last Post: 11-25-2008, 01:21 AM
  3. Java file reader...?
    By prabhurangan in forum New To Java
    Replies: 3
    Last Post: 11-21-2008, 08:19 AM
  4. [SOLVED] Need help with file reader
    By syed.shuvo in forum New To Java
    Replies: 6
    Last Post: 09-27-2008, 07:43 PM
  5. help with file reader
    By jason27131 in forum New To Java
    Replies: 1
    Last Post: 08-01-2007, 03:03 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •