模板如下
<div style="width:100%;height:450;overflow-x:auto;overflow-y:auto">
<table width="100%" border="1" cellspacing="2" cellpadding="0">
<tr id="title" bgcolor="#fefcce">
<td nowrap="true" >客户</td>
<td nowrap="true" >产品</td>
<td nowrap="true" >中文名称</td>
<td nowrap="true" >英文名称</td>
<td nowrap="true" >产品分类</td>
<td nowrap="true" >包装</td>
<td nowrap="true" >单位</td>
<td nowrap="true" >数量</td>
<td nowrap="true" >冻结数量</td>
<td nowrap="true" >可用数量</td>
<td nowrap="true" id="CUBIC"></td>
<td nowrap="true" id="WEIGHT"></td>
</tr>
<tr id="record">
<td nowrap="true" id="CUSTOMERID"></td>
<td nowrap="true" id="SKU_ID"></td>
<td nowrap="true" id="SKU_DESCR_C"></td>
<td nowrap="true" id="SKU_DESCR_E"></td>
<td nowrap="true" id="SKU_CLASS"></td>
<td nowrap="true" id="PACKAGE_ID"></td>
<td nowrap="true" id="UOM"></td>
<td nowrap="true" id="QUANTITY"></td>
<td nowrap="true" id="FREEZE_QUANTITY"></td>
<td nowrap="true" id="AVAILABLE_QUANTITY"></td>
<td nowrap="true" id="CUBIC"></td>
<td nowrap="true" id="WEIGHT"></td>
</tr>
</table>
</div>
public class ExcelTemplateUtil {
private static String CHARSET = "";
private static final String ROOT = "ROOT";
private static final String TITLE = "TITLE";
private static final String RECORD = "RECORD";
private static Map temp = new HashMap();
public static String generateListToTemplate(Object titleObj, List recordList, File templateFile)
{
readTemplateFile(templateFile);
ByteArrayOutputStream os = (ByteArrayOutputStream) builderExcelOutput(titleObj, recordList);
return removeXMLHeader(os);
}
public static void readTemplateFile(File file)
{
try {
Document templateDocument = new SAXReader().read(file);
Element root = templateDocument.getRootElement();
List trList = root.selectNodes("//div/table/tr");
Element titleTemp = (Element) trList.get(0);
Element recordTemp = (Element) trList.get(1);
root.element("table").remove(titleTemp);
root.element("table").remove(recordTemp);
temp.put(TITLE, trList.get(0));
temp.put(RECORD, trList.get(1));
temp.put(ROOT, root);
} catch (DocumentException e) {
e.printStackTrace();
throw new RuntimeException("Parse xml file error, Cause:", e);
}
}
public static OutputStream builderExcelOutput(Object titleObj, List list)
{
ByteArrayOutputStream os = new ByteArrayOutputStream();

