Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

CANNOT open excel wokrbook using POI

807591Mar 8 2008 — edited Mar 11 2008
Hi,

i have a major porblem that stops me from using the following code:
 
     POIFSFileSystem fs;
     HSSFWorkbook _wb = null;
      try
      {
          fs  = new POIFSFileSystem( new FileInputStream( "excelFile.xls") );
         _wb    = new HSSFWorkbook( fs );
      }
      catch ( FileNotFoundException e )
      {
         e.printStackTrace(  );
      }
      catch ( IOException e )
      {
         e.printStackTrace(  );
      }
     
     for(int i = 0; i < _wb.getNumberOfSheets();i++){
         HSSFSheet sheet = _wb.getSheetAt(0);
         for(Iterator rowIter = sheet.rowIterator();rowIter.hasNext();){
            HSSFRow row = (HSSFRow)rowIter.next();
            for(Iterator cellIter = row.cellIterator(); cellIter.hasNext();){
               HSSFCell cell = (HSSFCell)cellIter.next();
               //process the cell
            }
         }
      }
im creating a program that downlaods a certain excel file automaticaly and exports it to a tab limited text file. Using the above code it works on any excel file but not on the one im downloading...i keep getting the following error:
---
Exception in thread "main" java.lang.IllegalArgumentException: The supplied POIFSFileSystem contained neither a 'Workbook' entry, nor a 'WORKBOOK' entry. Is it really an excel file?
---
Now i know it is an excel file because i can open it in excel and even in its properties details it tells me its a 97-2003 version file. BUT when i open it in excel and save it as an Excel 97-2003 file and try it again, it works!

is there anything i can do to get this to work as this process needs to be automated and i can be doing it in excel myself.

PLEASE HELP!
Thanks! :)
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 8 2008
Added on Mar 8 2008
2 comments
145 views