Home arrow static arrow Java Programming [Archive] - XML -> Excel (XLS)
Warning: Creating default object from empty value in /www/htdocs/w008deb8/wiki/components/com_staticxt/staticxt.php on line 51
Java Programming [Archive] - XML -> Excel (XLS)
This topic has 16 replies on 2 pages.    1 | 2 | Next »

Posts:24
Registered: 4/21/03
XML -> Excel (XLS)  
Apr 26, 2004 12:33 AM



 
Does anyone know how to generate XLS file from XML source with using of java (no activex just crossplatform libs please)? I found that with using of Apache POI libs it's possible, but I didn't find any related documentation :(
 

Posts:107
Registered: 9/2/03
Re: XML -> Excel (XLS)  
Apr 26, 2004 2:32 AM (reply 1 of 16)



 
Use JAXB to create a schema for you XML files, then once you read them into objects, write out what you need into the various cells using the Apache HSSF stuff. There's some good documentation/examples for the HSSF stuff on the Apache site: http://jakarta.apache.org/poi/hssf/quick-guide.html#CreateDateCells

Alternatively, I guess you could use a SAX parser, but I prefer JAXB.

-G
 

Posts:24
Registered: 4/21/03
Re: XML -> Excel (XLS)  
Apr 26, 2004 2:55 AM (reply 2 of 16)



 
Thnx, the link for cells creating is really great! But could you describe the other steps in more details?
 

Posts:107
Registered: 9/2/03
Re: XML -> Excel (XLS)  
Apr 26, 2004 3:45 AM (reply 3 of 16)



 
Take a look at JAXB here: http://java.sun.com/xml/jaxb/users-guide/jaxb-works.html
It's part of the Java Web Services Development Platform. (JWSDP), just do a search through the java.sun.com site for it.

You can also look at: http://www.w3schools.com/schema/schema_facets.asp
For more information on XSD schemas.

-G
 

Posts:24
Registered: 4/21/03
Re: XML -> Excel (XLS)  
Apr 26, 2004 4:40 AM (reply 4 of 16)



 
Sorry if the question is stupid, but I'm new to JAXB (I use SAX). How can I implement HSSF stuff for created objects?
 

Posts:39
Registered: 4/14/04
Re: XML -> Excel (XLS)  
Apr 26, 2004 5:45 AM (reply 5 of 16)



 
If you e-mail me a copy of some XML I will have a look as I have an XLS JDBC Driver in controlled release.

http://nilostep.com

Do assign Dukes -first-, hmm please?
 

Posts:107
Registered: 9/2/03
Re: XML -> Excel (XLS)  
Apr 26, 2004 6:20 AM (reply 6 of 16)



 
Using JAXB objects is just like using a normal object. When you write to the cell, you use the getXYZ() method of the object. At first it may be easier to write all the cells out as Strings, and then work on formatting them later.

JAXB gives you parent-child relationship for an entire XML structure. The root element has various fields, and can then have 1-M children (Collection) of various Object types, which in turn, can also have 1-M children (Collection).

What I like about JAXB, is that with a few minor adjustments to the XSD, I can use Hibernate (www.hibernate.org) to write information to the database.

-G
 

Posts:24
Registered: 4/21/03
Re: XML -> Excel (XLS)  
Apr 26, 2004 11:52 PM (reply 7 of 16)



 
I am not going to use new database which store data in excel format, I am already using mySQL for my project. I need to export in XLS but not to store in it!
 

Posts:6,147
Registered: 11/9/00
Re: XML -> Excel (XLS)  
Apr 27, 2004 12:04 AM (reply 8 of 16)



 
It's generally a lot simpler to translate your data to cvs (comma separeted value) format, which is just a text format but which all spreadsheets can read.
 

Posts:24
Registered: 4/21/03
Re: XML -> Excel (XLS)  
Apr 27, 2004 12:22 AM (reply 9 of 16)



 
Unfortunatelly my managers wants me to export in XLS but not CSV.
 

Posts:6,147
Registered: 11/9/00
Re: XML -> Excel (XLS)  
Apr 27, 2004 12:24 AM (reply 10 of 16)



 
Unfortunatelly my managers wants me to export in XLS
but not CSV.

Have you suggested CSV? entirely possible they haven't heard of it.
 

Posts:24
Registered: 4/21/03
Re: XML -> Excel (XLS)  
Apr 27, 2004 12:31 AM (reply 11 of 16)



 
This problem was already discussed!
 

Posts:107
Registered: 9/2/03
Re: XML -> Excel (XLS)  
Apr 28, 2004 1:22 AM (reply 12 of 16)



 
I didn't say you HAVE to store it, I just said you COULD store it. JAXB is Java's way of turning an XML into an Object tree by parsing it through an XSD.

One you have it in an Object tree, simply traverse the various objects until you get to the collection you want to use for the rows in your XLS file, then write them out to the cells using HSSF.

Alternatively, you can use SAX to parse the XML file and as you hit each node that you know you should have in the XML file, simply write that into your XLS file in whichever cell you want. I suggested JAXB as you would then have an OO version of your XML file, from which you could select whichever specific set of data you wanted to use in your XLS file.

By having it all in Object tree, it would make changing what data needs to go into your XLS file quite simple.

-G
 

Posts:24
Registered: 4/21/03
Re: XML -> Excel (XLS)  
Apr 28, 2004 1:28 AM (reply 13 of 16)



 
Sorry Brannor, but that was a reply for another message (about XLS JDBC), your way of exporting XML in XLS is really great!
 

Posts:24
Registered: 4/21/03
Re: XML -> Excel (XLS)  
Apr 28, 2004 1:28 AM (reply 14 of 16)



 
Sorry Brannor, but that was a reply for another message (about XLS JDBC), your way of exporting XML in XLS is really great!
 
This topic has 16 replies on 2 pages.    1 | 2 | Next »