Back in June this year, Yuri and Axel worked on a solution for something 
similar and I have been able to recover some code Axel posted to the list. 
Sorry, it is not formatted correctly and I have not tested it myself but it may 
contain enough information for you to find out how to access data from embedded 
objects. I have simply copied it and pasted into this message below. will you 
let me know if you can make this work please? If not, I will have a deeper dig 
into the archive when I return home later today.

Good luck AA.

With great help from Yury I found the following principal solution which
might help others to solve similar questions.

(My original test input converted the embedded Excel table somehow to a Word
table (?))

---
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;

import org.apache.poi.hssf.record.RecordFormatException;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.poifs.eventfilesystem.POIFSReader;
import org.apache.poi.poifs.eventfilesystem.POIFSReaderEvent;
import org.apache.poi.poifs.eventfilesystem.POIFSReaderListener;
import org.apache.poi.poifs.filesystem.DirectoryNode;
import org.apache.poi.poifs.filesystem.POIFSDocumentPath;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;

public class POIFSExtract {

    public static void main(String[] args) throws Exception {
        if (args == null || args.length < 1)
            throw new Exception("\n->no input, no output<-");

        final String fileName = args[0];
        POIFSFileSystem fs = new POIFSFileSystem(new
FileInputStream(fileName));

        POIFSReader reader = new POIFSReader();
        reader.registerListener(new MyPOIFSReaderListener(fs));
        reader.read(new FileInputStream(fileName));
    }

    static class MyPOIFSReaderListener implements POIFSReaderListener {

        private POIFSFileSystem fs;

        public MyPOIFSReaderListener(POIFSFileSystem fs) {
            this.fs = fs;
        }

        public void processPOIFSReaderEvent(POIFSReaderEvent event) {

            String name = event.getName();
            POIFSDocumentPath path = event.getPath();
            System.out.println("got '" + name + "' event for path '" + path
+ "'.");

            if (name.endsWith("Workbook") || name.endsWith("WORKBOOK")) {
                try {
                    DirectoryNode dir = resolveDir(fs,
event.getPath().toString()); // converting it to DirectoryNode
                    System.out.println("  trying DirectoryNode '" +
dir.getName() + "'");
                    HSSFWorkbook wb = new HSSFWorkbook(dir, fs, true); //
Invoke HSSFWorkbook constructor passing this directory to it
                    System.out.println("  !!! success: workbook with " +
wb.getNumberOfSheets() + " sheets.");
                }
                catch (RecordFormatException e) {
                    // MS Graph charts are stored in "Workbook" stream too
                    System.out.println("  skipping embedded MS Graph
object!");
                }
                catch (Exception e) {
                    System.out.println("  " + e.getMessage());
                    throw new RuntimeException(e.getMessage());
                }
            }
        }

        static DirectoryNode resolveDir(POIFSFileSystem filesystem, String
path) throws FileNotFoundException {
            DirectoryNode dir = filesystem.getRoot();

            for (String token : path.split("\\" + File.separator)) {
                if (!token.equals("") && !token.equals(File.separator))
                    dir = (DirectoryNode) dir.getEntry(token);
            }

            return dir;
        }
    }
}
---

Cheers,
Axel.





--- On Wed, 11/5/08, Anthony Andrews <[EMAIL PROTECTED]> wrote:
From: Anthony Andrews <[EMAIL PROTECTED]>
Subject: RE: How to read Inserted Objects in EXCEL File
To: "POI Users List" <[email protected]>
Date: Wednesday, November 5, 2008, 12:15 AM

Think I have found the post I was looking for - from Dimitry and it related
specifically to zipped files in Excel 2007 sheets. Will continue searching
further later today - when I get back in from work. If I do find anything, I
will post again here.

In the meantime, have a look at the getAllEmbeddedObjects() methods defined on
the HSSFWorkbook class. Have never used it and do not know where it will take
you but it could be a start.

--- On Tue, 11/4/08, Anthony Andrews <[EMAIL PROTECTED]> wrote:
From: Anthony Andrews <[EMAIL PROTECTED]>
Subject: RE: How to read Inserted Objects in EXCEL File
To: "POI Users List" <[email protected]>
Date: Tuesday, November 4, 2008, 11:57 PM

Have never done this myself but I do remember a similar post a few months ago.
Will have a look through the archives and see what I can find.

--- On Tue, 11/4/08, Mits <[EMAIL PROTECTED]> wrote:
From: Mits <[EMAIL PROTECTED]>
Subject: RE: How to read Inserted Objects in EXCEL File
To: [email protected]
Date: Tuesday, November 4, 2008, 10:27 PM

Hello,

To be more Precise ,

I have requirement of one EXCEL file can contain another EXCEL File or DOC
file as Inserted Objects.

So when I have to read Parent EXCEL file , I need to first search that , it
contains any Attached or Inserted Objects. If I find , then I have to read
that Inserted Object (EXCEL) As well. usaully Maually we double click on to
the ICON of the Inserted File. I may or may not write in to that Attached /
Inserted EXCEL or DOC document & Save it.

I hope this clears a lot or still require some more detail Clarifications ?

Sorry for previous post... 

Can some one help me out with the Sample code of above requirement using POI
?

Thanks,








Anthony Andrews wrote:
> 
> Furthermore, it might help if you were a little more precise about exactly
> what you want to do. What sort of object are you dealing with an what do
> you want to do (i.e. what do you mean by 'read') with it?
> 
> Finally, have you searched the mail archive? I am fairly certain that
> someone else has asked this question recently.
> 
> --- On Tue, 11/4/08, Knudsen, Joe <[EMAIL PROTECTED]> wrote:
> From: Knudsen, Joe <[EMAIL PROTECTED]>
> Subject: RE: How to read Inserted Objects in EXCEL File
> To: "POI Users List" <[email protected]>
> Date: Tuesday, November 4, 2008, 7:19 AM
> 
> Look at the API documentation for Excel look at the HSSF classes.
> 
> -----Original Message-----
> From: Mits [mailto:[EMAIL PROTECTED] 
> Sent: Monday, November 03, 2008 11:00 PM
> To: [email protected]
> Subject: Re: How to read Inserted Objects in EXCEL File
> 
> 
> 
> 
> Mits wrote:
>> 
>> Hello All,
>> 
>> I have the requirement of Reading Inserted Objects from the EXCEL
> File.
>> 
>> Can some one help me out , Which POI API can help me out to Read that
> ?
>> 
>> Please reply if some one require some more detail explanation.
>> 
>> Thanks,
>> 
>> 
> 
> Atleast some one can let me know , Is it Possible to Read Inserted
> Objects
> in EXCEL Sheet using POI Jar?
> -- 
> View this message in context:
> http://www.nabble.com/How-to-read-Inserted-Objects-in-EXCEL-File-tp20296
> 909p20316247.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]
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
> 
> 
> 
>       
> 

-- 
View this message in context:
http://www.nabble.com/How-to-read-Inserted-Objects-in-EXCEL-File-tp20296909p20336708.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