这里只是代码片段,有好多数据变量要根据你们自己项目修改,不要完全照抄。这里考虑到多sheet功能。
/**
* 创建xml格式的excel头部。
* 大帅哥
*/
private void createExcelXmlHeader(String path){
if(document!=null){
return;
}
file = new File(path);
document = DocumentHelper.createDocument();
workBook = document.addElement("Workbook", "urn:schemas-microsoft-com:office:spreadsheet");
workBook.addAttribute("xmlns:o","urn:schemas-microsoft-com:office:office");
workBook.addAttribute("xmlns:x","urn:schemas-microsoft-com:office:excel");
workBook.addAttribute("xmlns:ss","urn:schemas-microsoft-com:office:spreadsheet");
workBook.addAttribute("xmlns:html","http://www.w3.org/TR/REC-html40");
workBook.addComment("备注");
Element styles = workBook.addElement("Styles");
styles.addElement("Style").addAttribute("ss:ID", "Default").addAttribute("ss:Name", "Normal");
Element style = styles.addElement("Style").addAttribute("ss:ID", "s15");
style.addElement("Alignment").addAttribute("ss:Vertical", "Bottom");
style.addElement("Borders");