2011-06-23 121 views
1

我想導出一個在asp中動態創建的html表,但是當我導出到excel時,所有的td都在Excel中的單個單元格中。任何想法如何使每個TD在Excel中不同的單元格?用ASP導出html到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> 

我從來沒有做過此之前,所以請原諒我草率的編碼。

回答

0

試試這個:

Response.Clear

Response.ContentType =「應用/ vnd.m S-EXCEL」

Response.addHeader 「內容處置」, 「附件;文件名= yourname.xls」

希望這有助於。

+0

謝謝,我試過了,沒有運氣。我嘗試使用上面的方法與靜態HTML表,它的工作原理,只是沒有動態構建。 – John