将Gridview数据导出到Excel-更改标题名称 [英] Export Gridview Data to Excel - Change the header name

查看:123
本文介绍了将Gridview数据导出到Excel-更改标题名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是否有可能更改从gridview导出的数据的标题名称?以下是我的代码及其正常工作.我唯一的问题是我无法更改标题名称.

Hi, is there a chance that I change the header name of the exported data from gridview? Below is my code and its working fine. My only problem is I can''t change the header name.

Dim strFilename As String = Now.Date.Month.ToString + Now.Date.Day.ToString + Now.Hour.ToString + Now.Minute.ToString + Now.Second.ToString

Response.AddHeader("content-disposition", "attachment;filename=" & strFilename & ".xls")
Response.Clear()
Response.Charset = ""
Response.ContentType = "application/vnd.ms-excel"

Dim stringWrite As System.IO.StringWriter = New System.IO.StringWriter()
Dim htmlWrite As System.Web.UI.HtmlTextWriter = New System.Web.UI.HtmlTextWriter(stringWrite)
Dim dg As System.Web.UI.WebControls.DataGrid = New System.Web.UI.WebControls.DataGrid()

dg.DataSource = dt
dg.DataBind()
dg.RenderControl(htmlWrite)
Response.Write(stringWrite.ToString())
Response.End()


结果是


The result is

ID  Fname     
1   aaa     
2   bbb     
3   ccc       



我要这样



I want like this

Employee ID  First Name     
1            aaa     
2            bbb      
3            ccc

推荐答案

DataTableColumn中进行更改.


我该如何更改-您能告诉我代码吗?谢谢
how can i change that - can you show me the code..thanks


这篇关于将Gridview数据导出到Excel-更改标题名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆