2013-12-17 162 views
0

我使用下面的命令將xml文件轉換爲excel文件,但是我無法生成xls文件,請告訴我該怎麼做?從xml文件生成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"); 
    } 
} 
+0

你讀的XML文件,請告訴我們,保存XLS文件的代碼 – OlimilOops

+0

其實這就是我要尋找「即保存XLS文件中的代碼」 – user2786306

+0

你有沒有試過XSerializer? – OlimilOops

回答

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二進制格式。
看看這裏:
https://stackoverflow.com/questions/18177870/how-can-i-read-or-write-xls-files-using-java