It may be the way you are creating the enbedded workbook object. I have
copied the example code from the Quick Guide;

It is possible to perform more detailed processing of an embedded Excel,
Word or PowerPoint document, or to work with any other type of embedded
object.

HSSF:

  POIFSFileSystem fs = new POIFSFileSystem(new
FileInputStream("excel_with_embeded.xls"));
  HSSFWorkbook workbook = new HSSFWorkbook(fs);
  for (HSSFObjectData obj : workbook.getAllEmbeddedObjects()) {
      //the OLE2 Class Name of the object
      String oleName = obj.getOLE2ClassName();
      if (oleName.equals("Worksheet")) {
          DirectoryNode dn = (DirectoryNode) obj.getDirectory();
          HSSFWorkbook embeddedWorkbook = new HSSFWorkbook(dn, fs, false);
          //System.out.println(entry.getName() + ": " +
embeddedWorkbook.getNumberOfSheets());
      } else if (oleName.equals("Document")) {
          DirectoryNode dn = (DirectoryNode) obj.getDirectory();
          HWPFDocument embeddedWordDocument = new HWPFDocument(dn, fs);
          //System.out.println(entry.getName() + ": " +
embeddedWordDocument.getRange().text());
      }  else if (oleName.equals("Presentation")) {
          DirectoryNode dn = (DirectoryNode) obj.getDirectory();
          SlideShow embeddedPowerPointDocument = new SlideShow(new
HSLFSlideShow(dn, fs));
          //System.out.println(entry.getName() + ": " +
embeddedPowerPointDocument.getSlides().length);
      } else {
          if(obj.hasDirectoryEntry()){
              // The DirectoryEntry is a DocumentNode. Examine its entries
to find out what it is
              DirectoryNode dn = (DirectoryNode) obj.getDirectory();
              for (Iterator entries = dn.getEntries(); entries.hasNext();) {
                  Entry entry = (Entry) entries.next();
                  //System.out.println(oleName + "." + entry.getName());
              }
          } else {
              // There is no DirectoryEntry
              // Recover the object's data from the HSSFObjectData instance.
              byte[] objectData = obj.getObjectData();
          }
      }
  }
       
That code has been tested against the latest 3.5 beta release but I think it
should work against 3.2 final as well.



stigman wrote:
> 
> I'm trying to read embedded objects in an excel spreadsheet and am getting
> "Unable to read entire header; 0 bytes read; expected 512 bytes" exception
> for all embedded objects when I try to read the embedded object. It can be
> another spreadsheet, word doc or ppt object. I'm able to read the docs
> individually with poi and when they are embedded in a ppt file using hslf.
> The exception is thrown when the new workbook object is creating. I've
> been struck on this problem and haven't been able to find anyone else with
> this issue, any help would be appreciated.
> 
> using poi 3.2final.
> excel spreadsheet is getting created with MS Excel 2000.
> 
> filename is an InputStream.
> 
> HSSFWorkbook wb = new HSSFWorkbook(filename, false);
> 
> for (Iterator<HSSFObjectData> doList =
> wb.getAllEmbeddedObjects().iterator(); doList.hasNext(); ) {
>               HSSFObjectData dataObject = (HSSFObjectData) doList.next();
>               if(dataObject.hasDirectoryEntry()){
>                       oleName = dataObject.getOLE2ClassName();
>               if("Worksheet".equals(oleName)){
>                           HSSFWorkbook wBook = new HSSFWorkbook(new
> ByteArrayInputStream(dataObject.getObjectData()));
>               }
>          }
> }
> 
> 
> 

-- 
View this message in context: 
http://www.nabble.com/embedded-objects-in-HSSF-tp24625249p24627925.html
Sent from the POI - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to