使用java将xml转换为xls

时间:2013-12-17 13:34:59

标签: java xml xls

我使用以下代码编写了一个xml文件,如何将该文件转换为xls或csv文件?我想读取一个xml文件并将其转换为xls文件使用java代码,有可能这样做吗?

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

} }

1 个答案:

答案 0 :(得分:1)

查看POIJXLS

POI是一个用Java编写office文档的库,JXLS可以基于模板生成Java的excel文档(模板也是一个excel文档)。请注意,JXLS是在POI之上实现的。