zoukankan      html  css  js  c++  java
  • 从Gridview 中导出数据到EXCEL

    前端:

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" EnableEventValidation="false" %>

    <asp:GridView ID="gv_Score" runat="server" CellPadding="4" ForeColor="#333333" AllowPaging="false">

    再定义一个按钮,实现导出功能。

    后台CS:

    using System.IO;

     protected void btn_Export_Click(object sender, EventArgs e)  

       {        

          Response.Charset="GB2312"; 

          Response.ContentEncoding=System.Text.Encoding.UTF8;

          Response.AddHeader("Content-Disposition","attachment;FileName="+HttpUtility.UrlEncode(DateTime.Now.ToString(),System.Text.Encoding.UTF8)+".xls");

         Response.ContentType = "application/ms-excel"; //输出文件类型为excel类型

         this.EnableViewState = false; 

         StringWriter wt = new StringWriter();  

          HtmlTextWriter hw = new HtmlTextWriter(wt);

           gv_Score.RenderControl(hw);      

        Response.Write(wt.ToString());     

        Response.End();    

    }    

    //必须覆写些方法,不然会报错。

    public override void VerifyRenderingInServerForm(Control control)   

      {

        }

  • 相关阅读:
    bzoj2287 [POJ Challenge]消失之物
    bzoj4504 K个串
    Tjoi2016&Heoi2016 字符串
    bzoj2555 SubString
    WC2017 游记
    《大灌篮》观后感
    Codeforces Round #394 (Div. 2)
    bzoj3489 A simple rmq problem
    Goodbye Bingshen
    COGS2216 你猜是不是KMP
  • 原文地址:https://www.cnblogs.com/liuyuanhao/p/3078905.html
Copyright © 2011-2022 走看看