Reputation: 221
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);
}
} }
Upvotes: 1
Views: 4533
Reputation: 27986
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.
Upvotes: 2