我使用下面的代码工作正常,我只想在DataGrid数据之前将自定义文本或图像添加到Excel工作表。
Response.Clear()
Response.AddHeader("content-disposition", "attachment;filename=TabelDetails.xls")
Response.Charset = ""
Response.Cache.SetCacheability(HttpCacheability.NoCache)
Response.ContentType = "application/vnd.xls"
Dim stringWrite As StringWriter = New StringWriter()
Dim htmlWrite As HtmlTextWriter = New HtmlTextWriter(stringWrite)
Me.datagrid.RenderControl(htmlWrite)
Response.Write(stringWrite.ToString())
Response.End()