使用ASP将html导出到Excel

时间:2011-06-23 20:06:38

标签: html excel asp-classic

我正在尝试导出在asp中动态创建的html表,但是当我导出到excel时,所有td都在Excel中的单个单元格中。有关如何在Excel中将每个td设置为不同单元格的任何想法吗?

这是我的代码:

<%  Set x = Server.CreateObject("MSXML2.ServerXMLHTTP") 
    st = "&getdata=yes"
    x.Open "POST","https://www.mysite.com/exportToExcel.asp?",false 
    x.setRequestHeader "Content-Type", "application/x-www-form-urlencoded" 
    x.send st
    %>
    <table>
    <thead><tr>
    <th>Account</th>
    <th>Company</th>
    <th>Street Address</th>
    <th>City</th>
    <th>State</th>
    <th>Zip</th>
    <th>Phone</th>
    </tr>
    </thead>
    <tbody>
    <%
    Response.ContentType = "application/excel"
    Response.AddHeader "content-disposition","attachment;filename=filename.xls"
    Response.Write(x.responseText)%>
    </tbody>
    </table>

我从来没有这样做过,所以请原谅我的草率编码。

2 个答案:

答案 0 :(得分:2)

答案 1 :(得分:0)

试试这个:

Response.Clear

Response.ContentType =“application / vnd.ms-excel”

Response.addHeader“content-disposition”,“attachment; filename = yourname.xls”

希望这有帮助。