2016-07-26 88 views
0

我有很多代碼的實例,我將一個gridview導出爲ex​​cel。直到最近這一直很好。我最近升級到了Windows 10(相同版本的Excel),並且無法使此功能在任何可用的頁面上工作。 Excel打開,但沒有工作表。爲了證實我的懷疑,我在Windows 7機器上進行了測試,結果表明它工作正常。有沒有我在升級過程中丟失的設置?出口代碼如下。ASP.Net Gridview導出爲Excel中的Windows 10

Protected Sub ExportButton_Click(sender As Object, e As EventArgs) Handles ExportButton.Click 
    SqlDataSource1.SelectCommand = "SELECT * FROM [MyTable]..." 

    Response.Clear() 

    Response.AddHeader("content-disposition", "attachment;filename=FileName.xls") 
    Response.Charset = "" 
    Response.ContentType = "application/vnd.xls" 

    Dim sw As New System.IO.StringWriter 
    Dim hw As New HtmlTextWriter(sw) 
    GridView1.Visible = True 
    GridView1.DataBind() 
    GridView1.RenderControl(hw) 

    Response.Write(sw.ToString) 
    Response.End() 
    GridView1.Visible = False 
End Sub 

Public Overrides Sub VerifyRenderingInServerForm(ByVal control As Control) 

End Sub 
+0

那麼你並不產生實際的Excel文件,所以這是不好的。您正在製作僞裝成XLS文件的HTML文件。您應該使用能夠生成真正XLSX文件的庫。 – mason

回答