gridview汇出EXCEL (ExportGridViewToExcel(dt, HttpContext.Current.Response);)
调用 ExportGridViewToExcel(dt, HttpContext.Current.Response);
private void ExportGridViewToExcel(DataTable tb, HttpResponse response)
{
response.Clear();
response.Charset = "";
response.AppendHeader("Content-Disposition", "attachment;filename=Excel.xls");
response.ContentEncoding = System.Text.Encoding.UTF8;//System.Text.Encoding.GetEncoding("GB2312");
response.ContentType = "application/ms-excel";
StringWriter stringWriter = new StringWriter();
HtmlTextWriter htmlTextWriter = new HtmlTextWriter(stringWriter);
GridView newDataGrid = new GridView();
newDataGrid.EnableViewState = false;
newDataGrid.AllowSorting = false;
newDataGrid.GridLines = GridLines.Vertical;
newDataGrid.HeaderStyle.Font.Bold = true;
newDataGrid.DataSource = tb.DefaultView;
newDataGrid.DataBind();
newDataGrid.RenderControl(htmlTextWriter);
response.Write(stringWriter.ToString());
}
gridview汇出EXCEL (ExportGridViewToExcel(dt, HttpContext.Current.Response);)的更多相关文章
- GridView导出Excel的超好样例
事实上网上有非常多关于Excel的样例,可是不是非常好,他们的代码没有非常全,读的起来还非常晦涩.经过这几天的摸索,最终能够完毕我想要导出报表Excel的效果了.以下是我的效果图. 一.前台的页面图 ...
- C#实现GridView导出Excel
using System.Data;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;using System. ...
- C# GridView 导出Excel表
出错1:类型“GridView”的控件“GridView1”必须放在具有 runat=server 的窗体标记内解决方案:在后台文件中重载VerifyRenderingInServerForm方法,如 ...
- ASP.NET gridview导出excel,防止繁体产生有乱码的方式
//1.先引用比如 : using System; using System.Collections.Generic; using System.Linq; using System.Web; usi ...
- GridView导出Excel(中文乱码)
public void OUTEXCEL(string items,string where) { DataSet ds = new StudentBLL().GetTable(items,where ...
- gridview导excel及解决导出中文乱码的方法
要全部展示数据,所以导出时要先将翻页取消,重新绑定数据:gridview的allowpaging属性设置为false,然后databind()一下 <%@ Page Language=" ...
- 慎用System.Web.HttpContext.Current
每当控制流离开页面派生的Web表单上的代码的时候,HttpContext类的静态属性Current可能是有用的. 使用这个属性,我们可以获取当前请求(Request),响应(Response),会话( ...
- Response.End(); 用HttpContext.Current.ApplicationInstance.CompleteRequest 代替
Response.End(); 会报异常 HttpContext.Current.ApplicationInstance.CompleteRequest 这里有个讨论的帖子很有意思:http://q. ...
- Context.Response.End(); VS HttpContext.Current.ApplicationInstance.CompleteRequest();
今天遇到一個問題,頁面Client端send一個ajax請求,然後在server端返回一個json的字符串 $.ajax({ url: "xxxxx.aspx", type: &q ...
随机推荐
- qt5中QPrinter的使用兼容性问题
qt5与qt4在QPrinter中使用的不同点如下: 在.pro文件中加入如下语句:
- 使用Cookie实现跨域单点登录的原理
对于构建分布式系统来说业务功能的物理部署会随着新业务模块的增加而增加或改变物理部署的位置.而每个用户都有统一的帐号作为我们登录系统时的一个认证.当新业务或子系统部署在不同的物理机上,我们去访问不同的业 ...
- Android学习---数据库的增删改查(sqlite CRUD)
上一篇文章介绍了sqlite数据库的创建,以及数据的访问,本文将主要介绍数据库的增删改查. 下面直接看代码: MyDBHelper.java(创建数据库,添加一列phone) package com. ...
- jQuery Mobile 图标
jQuery 图标 如需在 jQuery Mobile 中向按钮添加图标,请使用 data-icon 属性: <a href="#anylink" data-role=&qu ...
- android中ColorStateList及StateListDrawable设置Selector
写过android的代码相信大家对Selector并不陌生吧,下面来看看这段xml文件是如何定义的 <?xml version="1.0" encoding="ut ...
- 用clock()函数计算多项式的运行时间
百度百科中定义clock():clock()是C/C++中的计时函数,而与其相关的数据类型是clock_t.在MSDN中,查得对clock函数定义如下: clock_t clock(void) ; 简 ...
- WINDOWS下绑定ARP绑定网关
一.WINDOWS下绑定ARP绑定网关步骤一:在能正常上网时,进入MS-DOS窗口,输入命令:arp -a,查看网关的IP对应的正确MAC地址, 并将其记录下来.注意:如果已经不能上网,则先运行一次命 ...
- AC算法 及python实现
零 导言 软件安全课上,老师讲了AC算法,写个博客,记一下吧. 那么AC算法是干啥的呢? ——是为了解决多模式匹配问题.换句话说,就是在大字符串S中,看看小字符串s1, s2,...有没有出现. AC ...
- myeclipse,eclipse打开当前文件所在文件夹
方法一: eclipse打开当前文件所在文件夹的插件Run-->External Tools-->External Tools Configurations...new 一个 progra ...
- setAutoCommmit保持数据的完整性
setAutoCommit总的来说就是保持数据的完整性,一个系统的更新操作可能要涉及多张表,需多个SQL语句进行操作 循环里连续的进行插入操作,如果你在开始时设置了:conn.setAutoCommi ...