Imports System
Imports System.Text
Namespace to
Excel '功能:将
asp.net中DataGrid生成Excel文件下载。
'Mountains改进:1、支持中文 2、隐藏列不显示
'日期:2002.10.30
Public Class DataGridToCSV
Public Function GenerateFile(ByRef Page As System.Web.UI.Page, ByVal MyDataGrid As System.Web.UI.WebControls.DataGrid, ByVal FileName As String) As String
Dim resp As HttpResponse
Dim colCount As Integer = MyDataGrid.Columns.Count - 1
resp = Page.Response
resp.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312") '解决中文乱码之关键
'resp.Charset = "utf-8"
'resp.AddFileDependency(FileName)
'resp.ContentType = "Text/HTML"
''resp.AppendHeader("Content-Type", "text/html; charset=gb2312")
resp.AppendHeader("Content-Disposition", "attachment;filename=" + FileName) '必要,做成下载文件
Dim colHeaders As String = ""