日期:2014-05-20 浏览次数:20796 次
<%@ page contentType="text/html;charset=UTF-8" language="java"%> <%@ page import="java.util.*"%> <% String filename = "Excel"; filename = new String(filename.getBytes("UTF-8"), "ISO8859_1"); response.setContentType("application/vnd.ms-excel; charset=UTF-8"); response.setHeader("Content-disposition","attachment;filename="+filename+".xls"); %> <html> <head> <title>Save To Excel</title> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> </head> <body> <table border="1" id="Table2" cellspacing="0" cellpadding="0" width=100% height=100%> <% String[] th=new String[]{"姓名","年龄"}; out.println("<tr style=\"background-color:yellow\">"); if(th!=null) { for(int i=0;i<th.length;i++) { %> <td nowrap height="19" align="center"> <%=th[i]%> </td> <% } } out.println("</tr>"); %> <% java.util.List v = new ArrayList(); v.add(new String[]{"张三", "18"}); v.add(new String[]{"李四", "19"}); if(v!=null) { if(v.size() > 0) { for(int row=0; row<v.size(); row++) { out.println("<tr style=\"background-color:yellow\">"); for(int col=0; col<th.length; col++) { String[] str = (String[])v.get(row); %> <td height="19" align="center" style='mso-number-format:"\@"'> <%=str[col] %> </td> <% } out.println("</tr>"); } } } %> </table> </body> </html>
------解决方案--------------------
我给你一个提示 :word 或者是 excle 是不是可以存储为 xml的。你倒推一下不就能吧xml弄成word,excle了?而xml是标准的数据交流方式,无论什么语言都可以操作的。