I have some Excel spreadsheets that contain files embedded as OLE packages
(Insert->Object->From file). I want to retrieve the data for those files.
I've managed to use the API to retrieve the Shape object and get at the OLE
data but I don't fancy writing my own OLE reading code. Is there an API to
get at the data inside? I saw css.embed.OLESimpleStorage but I can't seem to
get anywhere with that. My code so far is (in Python):

        # ... setting up of OOo ...

        sheet = doc.Sheets.getByName('Sheet1')
        draw_page = sheet.DrawPage

        shape = draw_page.getByIndex(0)

        # CLSID 00000000-0000-0000-0000-000000000000 is a file??
        print 'CLSID:', shape.CLSID

        obj = shape.EmbeddedObject

        # Create a "storage" object to hold the data from our embedded
object
        storage_factory =
service_manager.createInstance('com.sun.star.embed.StorageFactory')
        storage = storage_factory.createInstance()

        # Store the data into the "Something" entry of our storage object
        obj.storeToEntry(storage, 'Something', (), ())

        str_elem = storage.openStreamElement('Something', ElementModes.READ)
        stream = str_elem.getInputStream()

        sfa =
service_manager.createInstance('com.sun.star.ucb.SimpleFileAccess')
        sfa.writeFile(file_url('test.txt'), stream)

Thanks,
David Roe

Reply via email to