You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by jselect <js...@gmail.com> on 2009/06/03 16:22:01 UTC

How to convert xml to xls

Hello!

I have the xml file:  http://www.nabble.com/file/p23852396/test.xls test.xls
. This file has xml format and can be opened by MS Excel. I tried to read
this file by poi:

....
Workbook workbook = WorkbookFactory.create(new FileInputStream("test.xls"));
...

I got exception:
Exception in thread "main" java.lang.IllegalArgumentException: Your
InputStream was neither an OLE2 stream, nor an OOXML stream

I opened this file in MS Excel and saved as real xls: test1.xls
I tried to read this file by POI - no exceptions!

And question: Is it possible to convert this xml file to xls using POI?

Thanks!
-- 
View this message in context: http://www.nabble.com/How-to-convert-xml-to-xls-tp23852396p23852396.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 convert xml to xls

Posted by jselect <js...@gmail.com>.
Thanks newsletter-42!

I tried xmlbeans. My code is below:
...
XmlObject xmlObject = XmlObject.Factory.parse(file);
...
And I got exception in this line:
org.apache.xmlbeans.XmlException: error: Unexpected element: CDATA

I think that I have to use jdom...


newsletter-42 wrote:
> 
> depends on your needs but if you only want to process the information 
> within the file. You could use xmlBeans (http://xmlbeans.apache.org/) to 
> read the xml file and process it that way.
> 
> Cheers
> 

-- 
View this message in context: http://www.nabble.com/How-to-convert-xml-to-xls-tp23852396p23868222.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 convert xml to xls

Posted by MSB <ma...@tiscali.co.uk>.
Thanks very much for that links newsletter-42!

I have to admit that I did not know that piece of software existed. Must get
it today and have a play.


newsletter-42 wrote:
> 
> MSB wrote:
>> Hello,
>>
>> You have got an Office 2003 xml file there, not an OpenXML file; it is an
>> early attempt by Microsoft to create an xml based file format for Excel
>> and
>> it is in that sense a 'valid' Office file format.
>>
>> Sadly, POI cannot interpret this file at all and that is why you saw the
>> exception when you tried to wrap it up in the InputStream and pass it to
>> WorkbookFactory(s) constructor. You do however have a number of options;
>>
>> * You could use Excel itself and manually open and save each file you
>> wish
>> to convert, as you already have done.
>> * If you have access to Visual Studio and can write Visual Basic or C#
>> code
>> then you could use a control that will allow you to control Excel
>> programmatically. This way you could automate a file conversion process
>> using Excel itself. Then once the file has been converted wither to the
>> binary or OpenXML formats, POI can be used to process it.
>> * If you are running on a stand alone PC on which a copy of Excel is
>> installed and using the Windows operating system, then you could use OLE
>> to
>> do something very similar from Java code. As above, POI can be used to
>> process the file following the conversion.
>> * If you have access to OpenOffice, it has a rather good API that is
>> accessible from Java code. You could use it to convert between the file
>> types for you - it is simply a matter of discovering the correct filter
>> to
>> use in this case. OpenOffice is good for all except the most complex
>> files
>> and you should be able to use POI to process the file following
>> conversion.
>> However, if you choose this route, it may be best to do all of the work
>> using OpenOffice's UNO api.
>> * Depending upon what you want to do with the file's contents, you could
>> create your own parser using core java code and either the SAX or Xerces
>> parsers. If you simply open the original xml file using a simple text
>> editor, you can see that the structure is not complex and, if all you
>> wish
>> to get at is the raw data it contains, this could be your best option.
>>
>> Hope that helps,
>>
>> Yours
>>
>> Mark B
>>
>>
>> jselect wrote:
>>   
>>> Hello!
>>>
>>> I have the xml file:  http://www.nabble.com/file/p23852396/test.xls
>>> test.xls . This file has xml format and can be opened by MS Excel. I
>>> tried
>>> to read this file by poi:
>>>
>>> ....
>>> Workbook workbook = WorkbookFactory.create(new
>>> FileInputStream("test.xls"));
>>> ...
>>>
>>> I got exception:
>>> Exception in thread "main" java.lang.IllegalArgumentException: Your
>>> InputStream was neither an OLE2 stream, nor an OOXML stream
>>>
>>> I opened this file in MS Excel and saved as real xls: test1.xls
>>> I tried to read this file by POI - no exceptions!
>>>
>>> And question: Is it possible to convert this xml file to xls using POI?
>>>
>>> Thanks!
>>>
>>>     
>>
>>   
> depends on your needs but if you only want to process the information 
> within the file. You could use xmlBeans (http://xmlbeans.apache.org/) to 
> read the xml file and process it that way.
> 
> Cheers
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
> For additional commands, e-mail: user-help@poi.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/How-to-convert-xml-to-xls-tp23852396p23864589.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 convert xml to xls

Posted by newsletter <ne...@energyts.com>.
MSB wrote:
> Hello,
>
> You have got an Office 2003 xml file there, not an OpenXML file; it is an
> early attempt by Microsoft to create an xml based file format for Excel and
> it is in that sense a 'valid' Office file format.
>
> Sadly, POI cannot interpret this file at all and that is why you saw the
> exception when you tried to wrap it up in the InputStream and pass it to
> WorkbookFactory(s) constructor. You do however have a number of options;
>
> * You could use Excel itself and manually open and save each file you wish
> to convert, as you already have done.
> * If you have access to Visual Studio and can write Visual Basic or C# code
> then you could use a control that will allow you to control Excel
> programmatically. This way you could automate a file conversion process
> using Excel itself. Then once the file has been converted wither to the
> binary or OpenXML formats, POI can be used to process it.
> * If you are running on a stand alone PC on which a copy of Excel is
> installed and using the Windows operating system, then you could use OLE to
> do something very similar from Java code. As above, POI can be used to
> process the file following the conversion.
> * If you have access to OpenOffice, it has a rather good API that is
> accessible from Java code. You could use it to convert between the file
> types for you - it is simply a matter of discovering the correct filter to
> use in this case. OpenOffice is good for all except the most complex files
> and you should be able to use POI to process the file following conversion.
> However, if you choose this route, it may be best to do all of the work
> using OpenOffice's UNO api.
> * Depending upon what you want to do with the file's contents, you could
> create your own parser using core java code and either the SAX or Xerces
> parsers. If you simply open the original xml file using a simple text
> editor, you can see that the structure is not complex and, if all you wish
> to get at is the raw data it contains, this could be your best option.
>
> Hope that helps,
>
> Yours
>
> Mark B
>
>
> jselect wrote:
>   
>> Hello!
>>
>> I have the xml file:  http://www.nabble.com/file/p23852396/test.xls
>> test.xls . This file has xml format and can be opened by MS Excel. I tried
>> to read this file by poi:
>>
>> ....
>> Workbook workbook = WorkbookFactory.create(new
>> FileInputStream("test.xls"));
>> ...
>>
>> I got exception:
>> Exception in thread "main" java.lang.IllegalArgumentException: Your
>> InputStream was neither an OLE2 stream, nor an OOXML stream
>>
>> I opened this file in MS Excel and saved as real xls: test1.xls
>> I tried to read this file by POI - no exceptions!
>>
>> And question: Is it possible to convert this xml file to xls using POI?
>>
>> Thanks!
>>
>>     
>
>   
depends on your needs but if you only want to process the information 
within the file. You could use xmlBeans (http://xmlbeans.apache.org/) to 
read the xml file and process it that way.

Cheers

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


Re: How to convert xml to xls

Posted by jselect <js...@gmail.com>.
Thanks Mark B!

I'm automation tester and I need to automate the test: to get information
from this xml file and compare with something. I can use jdom as tool which
can helps me to parse this xml. But POI is easiest lib for navigate by table
:)


MSB wrote:
> 
> Hello,
> 
> You have got an Office 2003 xml file there, not an OpenXML file; it is an
> early attempt by Microsoft to create an xml based file format for Excel
> and it is in that sense a 'valid' Office file format.
> 
> Sadly, POI cannot interpret this file at all and that is why you saw the
> exception when you tried to wrap it up in the InputStream and pass it to
> WorkbookFactory(s) constructor. You do however have a number of options;
> 
> * You could use Excel itself and manually open and save each file you wish
> to convert, as you already have done.
> * If you have access to Visual Studio and can write Visual Basic or C#
> code then you could use a control that will allow you to control Excel
> programmatically. This way you could automate a file conversion process
> using Excel itself. Then once the file has been converted wither to the
> binary or OpenXML formats, POI can be used to process it.
> * If you are running on a stand alone PC on which a copy of Excel is
> installed and using the Windows operating system, then you could use OLE
> to do something very similar from Java code. As above, POI can be used to
> process the file following the conversion.
> * If you have access to OpenOffice, it has a rather good API that is
> accessible from Java code. You could use it to convert between the file
> types for you - it is simply a matter of discovering the correct filter to
> use in this case. OpenOffice is good for all except the most complex files
> and you should be able to use POI to process the file following
> conversion. However, if you choose this route, it may be best to do all of
> the work using OpenOffice's UNO api.
> * Depending upon what you want to do with the file's contents, you could
> create your own parser using core java code and either the SAX or Xerces
> parsers. If you simply open the original xml file using a simple text
> editor, you can see that the structure is not complex and, if all you wish
> to get at is the raw data it contains, this could be your best option.
> 
> Hope that helps,
> 
> Yours
> 
> Mark B
> 

-- 
View this message in context: http://www.nabble.com/How-to-convert-xml-to-xls-tp23852396p23868139.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 convert xml to xls

Posted by MSB <ma...@tiscali.co.uk>.
Hello,

You have got an Office 2003 xml file there, not an OpenXML file; it is an
early attempt by Microsoft to create an xml based file format for Excel and
it is in that sense a 'valid' Office file format.

Sadly, POI cannot interpret this file at all and that is why you saw the
exception when you tried to wrap it up in the InputStream and pass it to
WorkbookFactory(s) constructor. You do however have a number of options;

* You could use Excel itself and manually open and save each file you wish
to convert, as you already have done.
* If you have access to Visual Studio and can write Visual Basic or C# code
then you could use a control that will allow you to control Excel
programmatically. This way you could automate a file conversion process
using Excel itself. Then once the file has been converted wither to the
binary or OpenXML formats, POI can be used to process it.
* If you are running on a stand alone PC on which a copy of Excel is
installed and using the Windows operating system, then you could use OLE to
do something very similar from Java code. As above, POI can be used to
process the file following the conversion.
* If you have access to OpenOffice, it has a rather good API that is
accessible from Java code. You could use it to convert between the file
types for you - it is simply a matter of discovering the correct filter to
use in this case. OpenOffice is good for all except the most complex files
and you should be able to use POI to process the file following conversion.
However, if you choose this route, it may be best to do all of the work
using OpenOffice's UNO api.
* Depending upon what you want to do with the file's contents, you could
create your own parser using core java code and either the SAX or Xerces
parsers. If you simply open the original xml file using a simple text
editor, you can see that the structure is not complex and, if all you wish
to get at is the raw data it contains, this could be your best option.

Hope that helps,

Yours

Mark B


jselect wrote:
> 
> Hello!
> 
> I have the xml file:  http://www.nabble.com/file/p23852396/test.xls
> test.xls . This file has xml format and can be opened by MS Excel. I tried
> to read this file by poi:
> 
> ....
> Workbook workbook = WorkbookFactory.create(new
> FileInputStream("test.xls"));
> ...
> 
> I got exception:
> Exception in thread "main" java.lang.IllegalArgumentException: Your
> InputStream was neither an OLE2 stream, nor an OOXML stream
> 
> I opened this file in MS Excel and saved as real xls: test1.xls
> I tried to read this file by POI - no exceptions!
> 
> And question: Is it possible to convert this xml file to xls using POI?
> 
> Thanks!
> 

-- 
View this message in context: http://www.nabble.com/How-to-convert-xml-to-xls-tp23852396p23854414.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