grideview导出excel gridview有10列数据,只想导出其中的某些列,如只到5列,而不是所有列。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 GridView导出的是表内容,既然导出5列,那就只显示5列就可以导出了 //导出Excel protected void Button1_Click(object sender, EventArgs e) { Export("application/ms-excel", "学生成绩报表.xls"); } //导出Excel函数 private void Export(string FileType, string FileName) { Response.Charset = "GB2312"; Response.ContentEncoding = System.Text.Encoding.UTF7; Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(FileName, Encoding.UTF8).ToString()); Response.ContentType = FileType; this.EnableViewState = false; StringWriter tw = new StringWriter(); HtmlTextWriter hw = new HtmlTextWriter(tw); GridView1.RenderControl(hw); Response.Write(tw.ToString()); Response.End(); } //导出方法,必须有!!!!!!!! public override void VerifyRenderingInServerForm(Control control) { } //导出Excel protected void Button1_Click(object sender, EventArgs e) { Export("application/ms-excel", "学生成绩报表.xls"); } //导出Excel函数 private void Export(string FileType, string FileName) { //在这里将你不想要的列隐藏掉即可。比如隐藏 6,7行 gridview1.Rows[6].visable=false; gridview1.Rows[7].visable=false; Response.Charset = "GB2312"; Response.ContentEncoding = System.Text.Encoding.UTF7; Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(FileName, Encoding.UTF8).ToString()); Response.ContentType = FileType; this.EnableViewState = false; StringWriter tw = new StringWriter(); HtmlTextWriter hw = new HtmlTextWriter(tw); GridView1.RenderControl(hw); Response.Write(tw.ToString()); Response.End(); } //导出方法,必须有!!!!!!!! public override void VerifyRenderingInServerForm(Control control) { } 放个隐藏的GridView设置成显示5列.导出这个隐藏的GridView的数据到EXCEL. gridview.rows中取出你要的gridviewrow数组,然后构造新的gridview对象,然后以新的gridview导出。最好好事好好研究下EXCEL,写个简单的EXCEL处理类并不复杂。 安装了SqlServer2005就不能创建aspNetDb.mdf了??!! 如何把公司内网主页加入到ie的受信站点? 求助!GV添加行的问题。 sql语句问题 怎样过滤文章中的敏感字 请教:控件逻辑中怎么控制母版中控件? 我没有分,你们会帮我吗? 急求树控件的优化?? 怎样学好asp.net 如何取出DataValueField,DataTextField中的值? 引用问题 高手们帮我看看Asp.net2.0+SQLServer2005连接
//导出Excel
protected void Button1_Click(object sender, EventArgs e)
{
Export("application/ms-excel", "学生成绩报表.xls");
}
//导出Excel函数
private void Export(string FileType, string FileName)
{
Response.Charset = "GB2312";
Response.ContentEncoding = System.Text.Encoding.UTF7;
Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(FileName, Encoding.UTF8).ToString());
Response.ContentType = FileType;
this.EnableViewState = false;
StringWriter tw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(tw);
GridView1.RenderControl(hw);
Response.Write(tw.ToString());
Response.End();
}
//导出方法,必须有!!!!!!!!
public override void VerifyRenderingInServerForm(Control control)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
Export("application/ms-excel", "学生成绩报表.xls");
}
//导出Excel函数
private void Export(string FileType, string FileName)
{
//在这里将你不想要的列隐藏掉即可。比如隐藏 6,7行
gridview1.Rows[6].visable=false;
gridview1.Rows[7].visable=false;
Response.Charset = "GB2312";
Response.ContentEncoding = System.Text.Encoding.UTF7;
Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(FileName, Encoding.UTF8).ToString());
Response.ContentType = FileType;
this.EnableViewState = false;
StringWriter tw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(tw);
GridView1.RenderControl(hw);
Response.Write(tw.ToString());
Response.End();
}
//导出方法,必须有!!!!!!!!
public override void VerifyRenderingInServerForm(Control control)
{
}