最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
问题解决了,先将改进代码贴出。(实现将DataGrid中数据倒出Excel文件并下载)
时间:2022-07-02 11:32:54 编辑:袖梨 来源:一聚教程网
Imports System
Imports System.Text
Namespace toExcel
'功能:将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 = ""
Imports System.Text
Namespace toExcel
'功能:将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 = ""
相关文章
- 人们熟悉的寄居蟹属于以下哪种分类 神奇海洋11月21日答案 11-21
- 第五人格11.22共研服有什么更新 11月22日共研服更新内容介绍 11-21
- 原神恰斯卡怎么培养 11-21
- 无期迷途四星装束是谁 11-21
- 王者荣耀帝丹高中校服怎么获得 11-21
- 光遇姆明季后续版本怎么玩 11-21