GridView 导出Excel
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的更多相关文章
- Asp.net Gridview导出Excel
前台页面放一个GridView什么的就不说了,要注意的是在 <%@ Page Language="C#" AutoEventWireup="true" C ...
- GridView导出Excel的超好样例
事实上网上有非常多关于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格式问题
在导出的点击事件中,代码如下: //指定导出对应单元格为文本样式 string style = @"<style> .test { vnd.ms-excel.numberform ...
- C# GridView 导出Excel表
出错1:类型“GridView”的控件“GridView1”必须放在具有 runat=server 的窗体标记内解决方案:在后台文件中重载VerifyRenderingInServerForm方法,如 ...
- GridView导出Excel(中文乱码)
public void OUTEXCEL(string items,string where) { DataSet ds = new StudentBLL().GetTable(items,where ...
- GridView导出Excel
public void OUTEXCEL() { DataSet ds = new GW_T_DemandDAL().GetWzH(GetPersonInfoData(UserInfo), Reque ...
- C#通过gridview导出excel
[CustomAuthorize] public FileResult ExportQuestionCenterExcel(SearchBaseQuestion search) ...
随机推荐
- 互斥体与互锁 <第五篇>
互斥体实现了“互相排斥”(mutual exclusion)同步的简单形式(所以名为互斥体(mutex)).互斥体禁止多个线程同时进入受保护的代码“临界区”.因此,在任意时刻,只有一个线程被允许进入这 ...
- SqlServer IF Exists([database]|[table]|[prop]) / Column([Operation])
*************************** --判断数据库是否存在 IF EXISTS (SELECT * FROM MASTER..sysdatabases WHERE NAME = ' ...
- FileAccess枚举
FileAccess用于控制对文件的读访问.写访问或读/写访问的常熟.从源代码可以看到FileAccess是一个简单枚举. 枚举成员 成员值 描述 Read 1 对文件的读访问,拥有读取权限. Wri ...
- 51 EEPROM操作模板
各个型号容量及扇区请查datasheet #include <reg52.h> #include "intrins.h" typedef unsigned char b ...
- bzoj1632 [Usaco2007 Feb]Lilypad Pond
Description Farmer John 建造了一个美丽的池塘,用于让他的牛们审美和锻炼.这个长方形的池子被分割成了 M 行和 N 列( 1 ≤ M ≤ 30 ; 1 ≤ N ≤ 30 ) 正方 ...
- Binary Tree Zigzag Level Order Traversal 解答
Question Given a binary tree, return the zigzag level order traversal of its nodes' values. (ie, fro ...
- 产生n bit所有可能的序列
void binary(int n) { ) printf("%s\n",A); // Assume A is a global variable else { A[n-] = ' ...
- Hibernate更新部分字段浅谈
update语句是在Hibernate的Configuration的时候生成的,不能动态改变.为什么update的时候所有的属性都一起update,而不是只更新改变字段,其实这是一个比较值得探讨的问题 ...
- ubuntu下安装xlrd模块,Mysqldb模块
Python中安装xlrd模块 1.从 https://pypi.python.org/pypi/xlrd 下载压缩包 2.解压所下载的压缩包 3.CD到解压文件夹,运行 sudo python s ...
- 使用lock_sga和pre_page_sga参数保证SGA常驻物理内存 .
Lock_sga LOCK_SGA locks the entire SGA into physical memory. It is usually advisable to lock the SGA ...