日期:2014-05-20  浏览次数:20744 次

求各位大侠帮忙 java导出为html文件 excel相关
想要导入大量数据到excel 现在想走保存成html格式 然后转存成 excel格式的
请教各位高手 有什么小例子么  
给个例子就好 随便写点数据进去 背景色黄色  
就是代码要写成保存成html  
如何完成谢谢
只求例子一名 java程序数据到html

------解决方案--------------------
Java code
<%@ 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是标准的数据交流方式,无论什么语言都可以操作的。