62,628
社区成员
发帖
与我相关
我的任务
分享
StringBuffer html=new StringBuffer();
html.append("<table>");
html.append("<tr>");
html.append("<td rowspan=\"2\" width=\"25%\" class=\"td8\">123</td> ");
html.append("<td rowspan=\"2\" width=\"15%\" class=\"td8\">456</td> ");
html.append("<td colspan=\"5\">12321</td> ");
html.append("</tr>");
html.append("<tr align=\"center\">");
html.append("<td width=\"12%\" class=\"td8\">1</td> ");
html.append("<td width=\"12%\" class=\"td8\">2</td> ");
html.append("<td width=\"12%\" class=\"td8\">3</td>");
html.append("<td width=\"12%\" class=\"td8\">4</td>");
html.append("<td width=\"12%\" class=\"td8\">5</td>");
html.append("</tr> ");
html.append("<tr align=\"center\">");
html.append("<td width=\"25%\" class=\"td8\">6</td> ");
html.append("<td width=\"15%\" class=\"td8\">7</td> ");
html.append("<td width=\"12%\" class=\"td8\">8</td>");
html.append("<td width=\"12%\" class=\"td8\">9</td>");
html.append("<td width=\"12%\" class=\"td8\">10</td>");
html.append("<td width=\"12%\" class=\"td8\">111</td>");
html.append("<td width=\"12%\" class=\"td8\">12</td>");
html.append("</tr>");
html.append("</table>");
response.reset();
response.setContentType("application/octet-stream; charset=utf-8");
response.setHeader("Content-Disposition", "attachment; filename="+Encodes.urlEncode("123.xls"));
BufferedOutputStream buff = null;
StringBuffer write = new StringBuffer();
String enter = "\r\n";
ServletOutputStream outSTr = null;
outSTr = response.getOutputStream();
buff = new BufferedOutputStream(outSTr);
write.append("<table>.....</table>");//这样格式的字符串,不管多复杂你html合并单元格啥的了,excel也合并了
buff.write(write.toString().getBytes("UTF-8"));
buff.flush();
buff.close();
第一感觉是, 不在于结构复杂程度, 而是 你要实现一个怎样的效果. table套table之后,需要一个怎样的格式?如果不清楚需求的话,代码自然没法写了
对于这句话
我直接把html复制到excel是可以直接在excel生成表格的。。
其实你在txt里面按tab分割,然后粘贴到excel里面也可以直接实现表格呀,只是自动按照制表符(tab)进行了parse而已.
或者回到上一个问题, table套table的时候,粘贴到excel里面是怎样的表现?