开发者

Export html to Excel with ASP

I am trying to export an html table dynamically created in asp however, when I export to excel, all the td's are in a single cell in Excel. Any ideas how to make each td a different cell in Excel?

Here is my code:

<%  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.respon开发者_如何学JAVAseText)%>
    </tbody>
    </table>

I have never done this before so excuse my sloppy coding.


Try look here:

Export Data to Excel using ASP

or here:

Building an Excel Spreadsheet using ASP


Try this :

Response.Clear

Response.ContentType = "application/vnd.ms-excel"

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

Hope this helps.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜