1
Response.Clear()
2
Response.BufferOutput = True
3
Response.Charset = "GB2312"
4
Response.AppendHeader("Content-Disposition", "attachment;filename=" & HttpUtility.UrlEncode("学员建议--" & Me.courseName, System.Text.Encoding.UTF8) & ".xls")
5
Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312")
6
Response.ContentType = "application/ms-excel"
7
dlstGetAndSuggest.EnableViewState = False
8
Dim myCItrad As New System.Globalization.CultureInfo("ZH-CN", True)
9
Dim oStringWriter As New System.IO.StringWriter(myCItrad)
10
Dim oHtmlTextWriter As New System.Web.UI.HtmlTextWriter(oStringWriter)
11
Me.dlstGetAndSuggest.RenderControl(oHtmlTextWriter)
12
Response.Write(oStringWriter.ToString())
13
Response.End()
说明:2
3
4
5
6
7
8
9
10
11
12
13
第4行,如果把文件名直接写作字符串格式,在导出时文件名会出现乱码,用HttpUtility.UrlEncode("学员建议--" & Me.courseName, System.Text.Encoding.UTF8),可以防止文件名为乱码。
第3行和第5行,防止原文中的内容导出到Excel文件时出现乱码。