用ASP将html导出到Excel

我试图导出一个在asp中dynamic创build的html表,但是当我导出到excel时,所有的td都在Excel中的单个单元格中。 任何想法如何使每个td在Excel中的不同单元格?

这是我的代码:

<% 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> 

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

试试看这里:

使用ASP将数据导出到Excel

或在这里:

使用ASP构buildExcel电子表格

尝试这个 :

Response.Clear

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

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

希望这可以帮助。