You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by MSB <ma...@tiscali.co.uk> on 2009/05/17 19:20:03 UTC

Re: How to get images from excel (both ole2 and ooxml)?!

Sorry about that, you are quite correct!

I had assumed that the getEscherAggregate.. method would have been defined
on the Sheet interface and carried over from HSSF to XSSF but that is not
the case. If I have the time, I will look into the way pictures are stored
in the xml package. I suspect that it will be possible to discover the
information you require by digging around in the relationships, but I do not
know this for a fact. If I manage to make any progress, I will let you know.

Of course, this could mean you will have to create two different ways to
handle pictures, one for the BIFF8 format files and another for OpenXML.


300Sadder wrote:
> 
> I can only find the only solution of getting the image from excel.
> List lst = workbook.getAllPictures();
> But the picture achieved cannot be identify the properties like file name,
> and the location in the excel.
> I want a function which can be used on excel 2003 and 2007.
> Is there a function exist? Is there a way to do it? 
> Or is this impossbile to do at this stage?
> Thanks.......
> 

-- 
View this message in context: http://www.nabble.com/How-to-get-images-from-excel-%28both-ole2-and-ooxml%29-%21-tp23573155p23585523.html
Sent from the POI - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org


Re: How to get images from excel (both ole2 and ooxml)?!

Posted by MSB <ma...@tiscali.co.uk>.
Have a look at this link;

http://poi.apache.org/spreadsheet/converting.html

and in particular, the section that is entitled 'New, generic SS Usermodel
Code'.

I think that you will be able to declare a variable of type
org.apache.poi.ss.usermodel.Workbook and then assign to it a reference to
either an HSSGWorkbook or an XSSFWorkbook. Further, you can use the
CreationHelper to create instances of the other classes you need to
manipulate the workbook.

Now, how you distinguish from an InputStream when you are getting a binary
or OpenXML file - and therefore when to generate and instance of the
HSSFWorkbook and when an XSSFWorkbook - is a separate issue and I think that
you want to look at the org.apache.poi.ss.usermodel.WorkbookFactory class.
One of the contructors has the following signature;

public static Workbook create(InputStream inp)

and, to quote from the javadoc, 'Creates the appropriate HSSFWorkbook /
XSSFWorkbook from the given InputStream. Your input stream MUST either
support mark/reset, or be wrapped as a PushbackInputStream.'

So, to sum up, you want to code to the Workbook interface, use the
CreationHelper and rely upon the static WorkbookFactory.create(InoutStream)
method.

Still looking into the pictures question. Unfortunately, I do not have
access to Office 2007 - I have updated the version of Office I do have so
that it has the necessary filters to read OpenXML files however - so I had
to wait until a friend of mine could create a .xlsx file with an image in it
for me to play with. Luckilly, it seems as if the Escher Layer had been
superceded in the OpenXML file format so it MUST be possible for us to do
what you require. I will have a play and let you know if I make any
progress; I think the key must be the drawing patriarch which is accessible
through the createDrawingPatriarch() method. If not them the CTDrawing bean
may the way to go, at least I do hope so.


300Sadder wrote:
> 
> True.
> Btw, do you know any method to distinguish the type of incoming excel?
> So two sections of codes can be used base on that.
> Thank you.
> 
> 
> MSB wrote:
>> 
>> Sorry about that, you are quite correct!
>> 
>> I had assumed that the getEscherAggregate.. method would have been
>> defined on the Sheet interface and carried over from HSSF to XSSF but
>> that is not the case. If I have the time, I will look into the way
>> pictures are stored in the xml package. I suspect that it will be
>> possible to discover the information you require by digging around in the
>> relationships, but I do not know this for a fact. If I manage to make any
>> progress, I will let you know.
>> 
>> Of course, this could mean you will have to create two different ways to
>> handle pictures, one for the BIFF8 format files and another for OpenXML.
>> 
>> 
>> 300Sadder wrote:
>>> 
>>> I can only find the only solution of getting the image from excel.
>>> List lst = workbook.getAllPictures();
>>> But the picture achieved cannot be identify the properties like file
>>> name, and the location in the excel.
>>> I want a function which can be used on excel 2003 and 2007.
>>> Is there a function exist? Is there a way to do it? 
>>> Or is this impossbile to do at this stage?
>>> Thanks.......
>>> 
>> 
>> 
> 
> 

-- 
View this message in context: http://www.nabble.com/How-to-get-images-from-excel-%28both-ole2-and-ooxml%29-%21-tp23573155p23599438.html
Sent from the POI - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org


Re: How to get images from excel (both ole2 and ooxml)?!

Posted by 300Sadder <la...@yahoo.com.hk>.
True.
Btw, do you know any method to distinguish the type of incoming excel?
So two sections of codes can be used base on that.
Thank you.


MSB wrote:
> 
> Sorry about that, you are quite correct!
> 
> I had assumed that the getEscherAggregate.. method would have been defined
> on the Sheet interface and carried over from HSSF to XSSF but that is not
> the case. If I have the time, I will look into the way pictures are stored
> in the xml package. I suspect that it will be possible to discover the
> information you require by digging around in the relationships, but I do
> not know this for a fact. If I manage to make any progress, I will let you
> know.
> 
> Of course, this could mean you will have to create two different ways to
> handle pictures, one for the BIFF8 format files and another for OpenXML.
> 
> 
> 300Sadder wrote:
>> 
>> I can only find the only solution of getting the image from excel.
>> List lst = workbook.getAllPictures();
>> But the picture achieved cannot be identify the properties like file
>> name, and the location in the excel.
>> I want a function which can be used on excel 2003 and 2007.
>> Is there a function exist? Is there a way to do it? 
>> Or is this impossbile to do at this stage?
>> Thanks.......
>> 
> 
> 

-- 
View this message in context: http://www.nabble.com/How-to-get-images-from-excel-%28both-ole2-and-ooxml%29-%21-tp23573155p23592571.html
Sent from the POI - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org