导出Excel Gridview
/// <summary>
/// 定义导出Excel的函数
/// </summary>
/// <param name="FileType"></param>
/// <param name="FileName"></param>
private void Export(string FileType, string FileName)
{
GridView1.AllowPaging = false; //导出分页的全部数据
GridView1.AllowSorting = false;
bind();
Response.Charset = "GB2312";
Response.ContentEncoding = System.Text.Encoding.UTF8;
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();
GridView1.AllowPaging = true; //导出分页的全部数据
GridView1.AllowSorting = true;
bind();
}
/// <summary>
/// 此方法必重写,否则会出错
/// </summary>
/// <param name="control"></param>
public override void VerifyRenderingInServerForm(Control control)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
Export("application/ms-excel", "123.xls");
}
还有由于是文件操作所以要引入名称空间IO和Text
using System.Drawing;
using System.IO;
using System.Text
轉:http://www.cnblogs.com/LifeKingcn/archive/2012/08/24/2654195.html
导出Excel Gridview的更多相关文章
- C#中 导入和导出Excel的方法
using System.Data; using System.Data.OleDb; /// <summary> /// Excel转为DataTable /// </summar ...
- Asp.net中导出Excel文档(Gridview)
主要思路,通过GridView来导出文档. 新建一个Aspx页面,页面创建GridView控件,后台绑定好数据源.然后load中直接打印即可导出 前台的GridView <asp:GridVie ...
- Asp.net Gridview导出Excel
前台页面放一个GridView什么的就不说了,要注意的是在 <%@ Page Language="C#" AutoEventWireup="true" C ...
- GridView导出Excel的超好样例
事实上网上有非常多关于Excel的样例,可是不是非常好,他们的代码没有非常全,读的起来还非常晦涩.经过这几天的摸索,最终能够完毕我想要导出报表Excel的效果了.以下是我的效果图. 一.前台的页面图 ...
- 【asp.net】将GridView数据导出Excel
概要: 中午睡了一会,醒来的时候看到老师叫我去办公室,需求是这样的,把excel表中的每个同学,判断图片目录中是否有对应的照片(图片的名字用的学号或身份证号码) 没有对应图片的学生记录,存入自己的数据 ...
- C#实现GridView导出Excel
using System.Data;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;using System. ...
- ASP.NET gridview导出excel,防止繁体产生有乱码的方式
//1.先引用比如 : using System; using System.Collections.Generic; using System.Linq; using System.Web; usi ...
- Gridview数据导出excel时身份证号码为科学计数法的解决方法
if (e.Row.RowType == DataControlRowType.DataRow) { string id = this.GridView1.DataKeys[e.Row.RowInde ...
- 将gridview 的数据导出EXCEL
gridview数据 单击“导出EXCEL”按钮后 1.在上面的代码中,先将gridview绑定到指定的数据源中,然后在button按钮(用来做导出到EXCEL的)的事件中,写入相关的代 ...
随机推荐
- HDU 2149 (巴什博奕) Public Sale
没什么好说的,一道水题. #include <cstdio> int main() { int n, m; ) { if(n <= m) { for(int i = n; i < ...
- 重装yum
1)卸载yum rpm -aq|grep yum|xargs rpm -e --nodeps 2)下载并安装python-urlgrabber,python-pycurl,yum-metadata-p ...
- 长期演进技术(LTE,Long Term Evolution)
/********************************************************************************* * 长期演进技术(LTE,Long ...
- ecshop 调用指定分类的推荐,热卖,新品
未测试 1.includes/lib_goods.php文件.把SQL语句改一下,与category表关联即可 将 $sql = 'SELECT g.goods_id,g.goods_name, g. ...
- canvas小知识
清单 1. 绘制 canvas 矩形 function drawRect(){ var canvas = document.getElementById('canvas'); if (canvas.g ...
- Intent(意图)
Intent的中文意思是“意图,目的”的意思,可以理解为不同组件之间通信的“媒介”或者“信使”. 目标组件一般要通过Intent来声明自己的条件,一般通过组件中的<intent-filter&g ...
- [转] 接触C# 反射 2
逆心 原文 反射基础,2013-4. 反射用于在程序运行过程中,获取类里面的信息或发现程序集并运行的一个过程.通过反射可以获得.dll和.exe后缀的程序集里面的信息.使用反射可以看到一个程序集内部的 ...
- 用标准C编写COM(一)
cdllbufferstruct编译器微软 目录(?)[-] 简介 COM对象和虚表 GUID QueryInterfaceAddRef and Release IClassFactory对象 打包到 ...
- UIImageView 点击放大缩小
static CGRect oldframe; -(void)showImage:(UIImageView *)avatarImageView{ UIImage *image=avatarImageV ...
- AngularJS自定义指令(Directives)在IE8下的一个坑
在项目中,由于要兼容到IE8,我使用1.2.8版本的angularJS.这个版本是支持自定义指令的.我打算使用自定义指令将顶部的header从其他页面分离.也就是实现在需要header的页面只用在&l ...