ASP.NET datable导出excel
本文转载:http://www.cnblogs.com/chwkai/archive/2005/10/08/250426.html
不错的文章:http://www.cnblogs.com/lzhp/archive/2012/08/02/2680763.html
不错文章:http://hcyu2012.blog.163.com/blog/static/165192580201132532526918/
public void DataTable2Excel(DataTable dtData)
{ if (dtData != null)
{ Response.Clear();
Response.Charset = "utf-8";
Response.AppendHeader("Content-Disposition", "attachment;filename= " + Server.UrlEncode("导出.xls"));
Response.ContentEncoding = System.Text.Encoding.GetEncoding("utf-8");
Response.ContentType = "application/ms-excel";//设置输出文件类型为excel文件.
this.EnableViewState = false;
System.Globalization.CultureInfo myCItrad = new System.Globalization.CultureInfo("ZH-CN", true);
System.IO.StringWriter stringWrite = new System.IO.StringWriter(myCItrad);
System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite); //// 为了解决dgData中可能进行了分页的情况,需要重新定义一个无分页的DataGrid
//System.Web.UI.WebControls.GridView dgExport = null;
//dgExport = new System.Web.UI.WebControls.GridView();
GridView dgExport = new GridView();
dgExport.AllowPaging = false;
dgExport.DataSource = dtData;
dgExport.DataBind();
for (int i = 1; i < dgExport.Rows.Count; i++)
{
dgExport.Rows[i].Cells[0].Attributes.Add("style", "mso-number-format:'0'");
dgExport.Rows[i].Cells[2].Attributes.Add("style", "mso-number-format:'\\@'");
} dgExport.RenderControl(htmlWrite);
Response.Write(stringWrite.ToString());
Response.Write(@"<style> .text { mso-number-format:'\\@';} </script> ");
Response.End(); }
} GridView export to excel 格式参考 mso-number-format:"0" NO Decimals
mso-number-format:"0\.000" 3 Decimals
mso-number-format:"\#\,\#\#0\.000" Comma with 3 dec
mso-number-format:"mm\/dd\/yy" Date7
mso-number-format:"mmmm\ d\,\ yyyy" Date9
mso-number-format:"m\/d\/yy\ h\:mm\ AM\/PM" D -T AMPM
mso-number-format:"Short Date" 01/03/1998
mso-number-format:"Medium Date" 01-mar-98
mso-number-format:"d\-mmm\-yyyy" 01-mar-1998
mso-number-format:"Short Time" 5:16
mso-number-format:"Medium Time" 5:16 am
mso-number-format:"Long Time" 5:16:21:00
mso-number-format:"Percent" Percent - two decimals
mso-number-format:"0%" Percent - no decimals
mso-number-format:"0\.E+00" Scientific Notation
mso-number-format:"\@" Text
mso-number-format:"\#\ ???\/???" Fractions - up to 3 digits (312/943)
mso-number-format:"\0022?\0022\#\,\#\#0\.00" ?12.76
mso-number-format:"\#\,\#\#0\.00_ \;\[Red\]\-\#\,\#\#0\.00\ " 2 decimals, negative numbers in red and signed
(1.56 -1.56)
ASP.NET datable导出excel的更多相关文章
- asp.net中导出Excel的方法
一.asp.net中导出Excel的方法: 本文转载 在asp.net中导出Excel有两种方法,一种是将导出的文件存放在服务器某个文件夹下面,然后将文件地址输出在浏览器上:一种是将文件直接将文件输出 ...
- ASP.net中导出Excel的简单方法介绍
下面介绍一种ASP.net中导出Excel的简单方法 先上代码:前台代码如下(这是自己项目里面写的一点代码先贴出来吧) <div id="export" runat=&quo ...
- 关于asp.net C# 导出Excel文件 打开Excel文件格式与扩展名指定格式不一致的解决办法
-----转载:http://blog.csdn.net/sgear/article/details/7663502 关于asp.net C# 导出Excel文件 打开Excel文件格式与扩展名指定格 ...
- ASP.NET MVC导出excel
ASP.NET MVC导出excel 要在ASP.NET MVC站点上做excel导出功能,但是要导出的excel文件比较大,有几十M,所以导出比较费时,为了不影响对界面的其它操作,我就采用异步的方式 ...
- C# asp.net中导出Excel表时总出现"只能在执行 Render() 的过程中调用 RegisterForEventValidation
C# asp.net中导出Excel表时总出现"只能在执行 Render() 的过程中调用 RegisterForEventValidation 后台添加以下方法:/// <summa ...
- ASP.NET MVC导出excel(数据量大,非常耗时的,异步导出)
要在ASP.NET MVC站点上做excel导出功能,但是要导出的excel文件比较大,有几十M,所以导出比较费时,为了不影响对界面的其它操作,我就采用异步的方式,后台开辟一个线程将excel导出到指 ...
- Asp.net中导出Excel文档(Gridview)
主要思路,通过GridView来导出文档. 新建一个Aspx页面,页面创建GridView控件,后台绑定好数据源.然后load中直接打印即可导出 前台的GridView <asp:GridVie ...
- Asp.net Gridview导出Excel
前台页面放一个GridView什么的就不说了,要注意的是在 <%@ Page Language="C#" AutoEventWireup="true" C ...
- ASP.NET导入导出Excel方法大全
本文介绍下,C#实现的可以导出与导入excel的代码一例,有需要的朋友,参考下吧. C#实现导出与导入excel.代码1: 复制代码 代码示例:#region 导出Excel /// <su ...
随机推荐
- 【实习记】2014-08-26都是回车惹的祸——shell脚本必须是unix行尾
事情由起:svn的url在excel里,我复制到txt文本下,vi做些文本处理,只提取了url,保存为url.txt.再用vi处理url.txt,加上svn checkout等词,变成可以运行 ...
- eclipse/ggts/myeclipse清除SVN用户名和密码
很多时候我们在使用eclipse/myeclipse/ggts这些开发工具进行开发的时候会有多个项目存在,不同的项目又存放在不同的svn下,需要进行svn之间的切换,如果你在创建资源库位置的时候保存了 ...
- configure: error: Cannot find libmysqlclient under /usr Note that the MySQL client library is not bundled anymore! 报错解决
错误说明 今天在centos 6.3 64位版本上安装PHP5.4.3时在./configure 步骤的时候出现了下面错误configure: error: Cannot find libmysqlc ...
- js常用字符串函数
// JS字符串 //1.replace字符串替换,只能换第一部分,就是说多个字符相同,只能换下最先的 var str='helloworld!'; alert(str.replace('llo',' ...
- VC杂记
获得Combobox的状态:向ComboBox发送CB_GETDROPPEDSTATE消息. 格式化字串:char buff[10] ; sprintf(buff,"1+1=%d" ...
- 配置nginx支持thinkphp框架
因为nginx本身没有支持pathinfo,所以无法使用thinkphp框架,不过我们可以在配置里进行修改使其能够正常使用thinkphp. 1.修改配置支持pathinfo vi /etc/ngin ...
- Opencv实现的简易绘图工具
第一次写博,还是个菜鸟.最近开始学习Opencv,试着写了个简易的绘图工具(目前只写了画线和橡皮擦部分,画其它图形还有待往里添加),也算是记录自己的学习之路. #include "stdaf ...
- hadoop Yarn 编程API
客户端编程库: 所在jar包: org.apache.hadoop.yarn.client.YarnClient 使用方法: 1 定义一个YarnClient实例: private YarnClien ...
- hustoj 1017 - Exact cover dancing link
1017 - Exact cover Time Limit: 15s Memory Limit: 128MB Special Judge Submissions: 5851 Solved: 3092 ...
- POJ Code the Tree 树的pufer编号
Code the Tree Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 2259 Accepted: 859 Desc ...