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);
}

} }

3
  • 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... Commented Dec 17, 2013 at 13:40
  • If you want to do it by yourself, take a look at this answer: stackoverflow.com/a/3367912/2829009 Commented Dec 17, 2013 at 13:43
  • 1
    possible duplicate of Converting xml file into an xls file Commented Jan 23, 2014 at 12:35

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.