我正在尝试将数据网格导出到 excel 文件。它正确转换了 asp:BoundColumn,但无法转换带有链接按钮或图像按钮的模板列。这些单元格将转换为空单元格。
这是将控件导出到 excel 的代码。,
Public Shared Sub Export(ByVal Mime As String, ByVal Filename As String, ByVal Response As HttpResponse, ByVal Control As Control)
Dim stringWrite As New System.IO.StringWriter()
Dim htmlWrite As New System.Web.UI.HtmlTextWriter(stringWrite)
Response.Clear()
Response.Buffer = True
Response.Charset = String.Empty
Response.ContentType = Mime
Response.AddHeader("Content-Disposition", "filename=" & Filename)
Control.RenderControl(htmlWrite)
Response.Write("<!DOCTYPE html PUBLIC ""-//W3C//DTD XHTML 1.0 Transitional//EN"" ""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd""><html xmlns=""http://www.w3.org/1999/xhtml""><head id=""Head1"" runat=""server""><meta http-equiv=""content-type"" content=""text-html; charset=utf-8""></head><body>" & stringWrite.ToString & "</body></html>")
Response.End()
End Sub
问题可能出在哪里?有任何想法吗?提前致谢。