从xml文件生成xls文件

时间:2013-12-17 14:31:14

标签: java xml xls

我使用下面的命令将xml文件转换为excel文件,但我无法生成xls文件,请告知如何做到这一点?

import java.io.File;
import java.io.IOException;
import javax.xml.parsers.ParserConfigurationException;
import org.apache.poi.hssf.model.Workbook;

//import nl.fountain.xelem.excel.Workbook;
import nl.fountain.xelem.lex.ExcelReader;
import org.xml.sax.SAXException;

public class XmlToXls11 {
    public void XML() throws ParserConfigurationException, SAXException, IOException
    {
        ExcelReader reader = new ExcelReader();
        Workbook xlWorkbook = (Workbook) reader.getWorkbook("c:/book.xml");
    }
}

1 个答案:

答案 0 :(得分:0)

你试过XSerializer吗?

public void writeExcelXmlFile(String fileNameIn, String fileNameOut){
XLDocument xldoc = new XLDocument(fileNameIn);
OutputStream out;
try {
    out = new BufferedOutputStream(new FileOutputStream(fileNameOut));
    new XSerializer().serialize(xldoc.getDocument(), out);
    out.close();    
} catch (XelemException e) {
    e.printStackTrace();
} catch (IOException e) {
    e.printStackTrace();
}
}

我想用这个库编写旧的xls-binary格式是不可能的 看看这里:
https://stackoverflow.com/questions/18177870/how-can-i-read-or-write-xls-files-using-java