简体   繁体   English

从xml文件生成xls文件

[英]Generating an xls file from an xml file

I am using the below command to convert an xml file to an excel file, but I could not generate the xls file, please advise how to do that? 我正在使用以下命令将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");
    }
}

have you tried the XSerializer? 您是否尝试过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();
}
}

I guess that it's not possible to write the old xls-binary format with this library. 我猜想不可能用该库编写旧的xls-binary格式。
have a look here: 在这里看看:
https://stackoverflow.com/questions/18177870/how-can-i-read-or-write-xls-files-using-java https://stackoverflow.com/questions/18177870/how-can-i-read-or-write-xls-files-using-java

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM