1

I wrote an xml file using the below codes, how to convert that file into xls or csv file? I want to read an xml file and covert it into an xls file using java codes, is there a possible way to do that?

        // write the content into xml file
TransformerFactory transformerFactory = TransformerFactory.newInstance();
    try {
        Transformer transformer = transformerFactory.newTransformer();
        DOMSource source = new DOMSource(doc);
        StreamResult result = new StreamResult(new File("C:\\file.xml"));
        try {
            // Output to console for testing
            // StreamResult result = new StreamResult(System.out);
            transformer.transform(source, result);

        } catch (TransformerException ex) {
            Logger.getLogger(CreditBureau.class.getName()).log(Level.SEVERE, null, ex);
        }
             System.out.println("File saved!");

    } catch (TransformerConfigurationException ex) {
        Logger.getLogger(CreditBureau.class.getName()).log(Level.SEVERE, null, ex);
    }

} catch (ParserConfigurationException ex) {
    Logger.getLogger(CreditBureau.class.getName()).log(Level.SEVERE, null, ex);
}

} }

user2786306
  • 221
  • 2
  • 6
  • 12
  • Yes, there is a possible way, but you need to try yourself first then come back here with some code... Basically it can get quite tricky though as xls or csv aren't really suited to represent a tree... – Laurent S. Dec 17 '13 at 13:40
  • If you want to do it by yourself, take a look at this answer: http://stackoverflow.com/a/3367912/2829009 – Manuel Allenspach Dec 17 '13 at 13:43
  • 1
    possible duplicate of [Converting xml file into an xls file](http://stackoverflow.com/questions/20633650/converting-xml-file-into-an-xls-file) – SANN3 Jan 23 '14 at 12:35

1 Answers1

2

Take a look at POI and JXLS

POI is a library for writing office documents in Java and JXLS can generate excel documents in Java based on a template (the template is also an excel document). Note that JXLS is implemented on top of POI.

lance-java
  • 25,497
  • 4
  • 59
  • 101