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. sql每五秒插入一条数据 一次插入N条数据

    1建立数据表 create table projectManage ( ID int identity primary key not null, projectName )not null, man ...

  2. Improving the AbiWord's Piece Table

    Improving the AbiWord's Piece Table[转] One of the most critical parts of any word processor is the b ...

  3. 设置PlaceHolder的颜色

    input::-webkit-input-placeholder{ color:green; } input::-webkit-input-placeholder { color: #999; } i ...

  4. 扩展ArcGIS API for Silverlight/WPF 中的TextSymbol支持角度标注

    原文 http://blog.csdn.net/esricd/article/details/7587136 在ArcGIS API for Silverlight/WPF中原版的TextSymbol ...

  5. Apache、php、mysql单独安装配置

    php, 安装版的,http://www.php.net/manual/zh/install.php.也有不安装版直接配置的. 在Windows 7下如何进行PHP配置环境. PHP环境在Window ...

  6. github page使用

    github page介绍: https://help.github.com/categories/20/articles 使用GitHub Pages建立博客 与GitHub建立好链接之后,就可以方 ...

  7. 多个ORACLE HOME的情况,默认的ORACLE HOME是哪个,以及如何更改HOME

    如果系统里安装了多个ORACLE产品,那么在注册表里,有可能也会有多个ORACLE HOME,在不设置系统环境变量的情况下,默认情况使用哪个ORACLE HOME? HKEY_LOCAL_MACHIN ...

  8. UESTC_Tournament CDOJ 124

    A sports company is planning to advertise in a tournament. It is a single round-robin tournament, th ...

  9. 【LeetCode练习题】Combination Sum

    Combination Sum Given a set of candidate numbers (C) and a target number (T), find all unique combin ...

  10. hdu 5495 LCS

    Problem Description You are given two sequence {a1,a2,...,an} and {b1,b2,...,bn}. Both sequences are ...