Reputation: 21
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.responseText)%>
</tbody>
</table>
I have never done this before so excuse my sloppy coding.
Upvotes: 1
Views: 12682
Reputation: 415
Try this :
Response.Clear
Response.ContentType = "application/vnd.ms-excel"
Response.addHeader "content-disposition","attachment;filename=yourname.xls"
Hope this helps.
Upvotes: 0
Reputation: 13086
Try look here:
Export Data to Excel using ASP
or here:
Building an Excel Spreadsheet using ASP
Upvotes: 2