protected void btnExcel_Click(object sender, EventArgs e)
{
if (GridView1.Rows.Count > )
{
ExportGridViewForUTF8(GridView1, DateTime.Now.ToShortDateString() + ".xls");//调用导出方法
} }
/// <summary>
/// 重载,否则出现“类型“GridView”的控件“GridView1”必须放在具有 runat=server 的窗体标... ”的错误
/// </summary>
/// <param name="control"></param>
public override void VerifyRenderingInServerForm(Control control)
{
//base.VerifyRenderingInServerForm(control);
}
/// <summary>
/// 导出方法
/// </summary>
/// <param name="GridView"></param>
/// <param name="filename">保存的文件名称</param>
private void ExportGridViewForUTF8(GridView GridView, string filename)
{
GridView1.AllowPaging = false;--去除GridView的分页
Bind();
string attachment = "attachment; filename=" + filename; Response.ClearContent();
Response.Buffer = true;
Response.AddHeader("content-disposition", attachment); Response.Charset = "UTF-8";
Response.ContentEncoding = System.Text.Encoding.GetEncoding("UTF-8");
Response.ContentType = "application/ms-excel";
System.IO.StringWriter sw = new System.IO.StringWriter(); HtmlTextWriter htw = new HtmlTextWriter(sw);
GridView.RenderControl(htw); Response.Output.Write(sw.ToString());
Response.Flush();
Response.End(); }

GridView 导出Excel的更多相关文章

  1. Asp.net Gridview导出Excel

    前台页面放一个GridView什么的就不说了,要注意的是在 <%@ Page Language="C#" AutoEventWireup="true" C ...

  2. GridView导出Excel的超好样例

    事实上网上有非常多关于Excel的样例,可是不是非常好,他们的代码没有非常全,读的起来还非常晦涩.经过这几天的摸索,最终能够完毕我想要导出报表Excel的效果了.以下是我的效果图. 一.前台的页面图 ...

  3. C#实现GridView导出Excel

    using System.Data;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;using System. ...

  4. ASP.NET gridview导出excel,防止繁体产生有乱码的方式

    //1.先引用比如 : using System; using System.Collections.Generic; using System.Linq; using System.Web; usi ...

  5. GridView导出excel格式问题

    在导出的点击事件中,代码如下: //指定导出对应单元格为文本样式 string style = @"<style> .test { vnd.ms-excel.numberform ...

  6. C# GridView 导出Excel表

    出错1:类型“GridView”的控件“GridView1”必须放在具有 runat=server 的窗体标记内解决方案:在后台文件中重载VerifyRenderingInServerForm方法,如 ...

  7. GridView导出Excel(中文乱码)

    public void OUTEXCEL(string items,string where) { DataSet ds = new StudentBLL().GetTable(items,where ...

  8. GridView导出Excel

    public void OUTEXCEL() { DataSet ds = new GW_T_DemandDAL().GetWzH(GetPersonInfoData(UserInfo), Reque ...

  9. C#通过gridview导出excel

    [CustomAuthorize]        public FileResult ExportQuestionCenterExcel(SearchBaseQuestion search)      ...

随机推荐

  1. 指定g++ 头文件路径的方法

    问题: 尝试引用Python.h 这个头文件 g++ -o main main.cpp main.:: 错误:Python.h:没有那个文件或目录 由些可以看出是g++ 找不到指定的头文件 解决方式: ...

  2. 深入理解JS原型链与继承

    我 觉得阅读精彩的文章是提升自己最快的方法,而且我发现人在不同阶段看待同样的东西都会有不同的收获,有一天你看到一本好书或者好的文章,请记得收藏起来, 隔断时间再去看看,我想应该会有很大的收获.其实今天 ...

  3. jQuery EasyUI求助

    最近在学习easyui的时候遇到了一个很奇怪的问题,在使用datagrid组件的时候,我想自定义一个列,用来显示一个查看详细页面的链接,但是当这个列不是最后一列的时候,链接一直显示不出来,求大神们指点 ...

  4. underscoreJS的Collections 的API

    <!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  5. B-树、B+树、B*树的区别

      原文地址:  http://blog.csdn.net/dazhong159/article/details/7963846/ B-树.B+树.B*树的区别 2012-09-11 22:41 97 ...

  6. Linux的环境变量配置

    以下都是环境变量相关的配置文件 1)/etc/enviroment 是系统的环境变量. (2)/etc/profile: 是所有用户的环境变量.当用户第一次登录时,该文件被执行. 并从/etc/pro ...

  7. 【转】Linux驱动模块编译进内核中

    原文网址:http://blog.chinaunix.net/uid-29287950-id-4573481.html BQ27501驱动编译进内核 一.       驱动程序编译进内核的步骤 在 l ...

  8. [Ext JS 4] 实战之多选下拉单 (带checkbox)

    前言 Ext js 创建一个多选下拉单的方式很简单, 使用Ext.form.ComboBox, 设置 multiSelect 为true 就可以了. 但是如果要在每个下拉之前加上一个checkbox, ...

  9. ID(dfs+bfs)-hdu-4127-Flood-it!

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4127 题目意思: 给n*n的方格,每个格子有一种颜色(0~5),每次可以选择一种颜色,使得和左上角相 ...

  10. 【巧妙的模拟】【UVA 10881】 - Piotr's Ants/Piotr的蚂蚁

    </pre></center><center style="font-family: Simsun;font-size:14px;"><s ...