zoukankan
html css js c++ java
Excel导出及数据格式化处理
public
void
ToExcel(System.Web.UI.Control ctl,
string
FileName)
{
HttpContext.Current.Response.Charset
=
"
UTF-8
"
;
HttpContext.Current.Response.ContentEncoding
=
System.Text.Encoding.Default;
HttpContext.Current.Response.ContentType
=
"
application/ms-excel
"
;
HttpContext.Current.Response.AppendHeader(
"
Content-Disposition
"
,
"
attachment;filename=
"
+
""
+
FileName
+
"
.xls
"
);
ctl.Page.EnableViewState
=
false
;
System.IO.StringWriter tw
=
new
System.IO.StringWriter();
HtmlTextWriter hw
=
new
HtmlTextWriter(tw);
ctl.RenderControl(hw);
HttpContext.Current.Response.Write(tw.ToString());
HttpContext.Current.Response.End();
}
public
override
void
VerifyRenderingInServerForm(Control control)
{
//
base.VerifyRenderingInServerForm(control);
}
protected
void
myGridView_RowDataBound(
object
sender, GridViewRowEventArgs e)
{
if
(e.Row.RowType
==
DataControlRowType.DataRow)
{
//
e.Row.Cells[0].Attributes.Add("style", "vnd.ms-excel.numberformat:@");
//
这里是将要导出到execl里的第一列格式化为字符类型。
//
e.Row.Cells[3].Attributes.Add("style", "vnd.ms-excel.numberformat:¥#,###.00");
//
这里是格式化为货币类型。
e.Row.Cells[
4
].Attributes.Add(
"
style
"
,
"
vnd.ms-excel.numberformat:@
"
);
//
1) 文本:vnd.ms-excel.numberformat:@
//
2) 日期:vnd.ms-excel.numberformat:yyyy/mm/dd
//
3) 数字:vnd.ms-excel.numberformat:#,##0.00
//
4) 货币:vnd.ms-excel.numberformat:¥#,##0.00
//
5) 百分比:vnd.ms-excel.numberformat: #0.00%
}
}
查看全文
相关阅读:
【转帖】太晚睡觉等于自杀(一定要看看,以后不熬夜了!)程序员必看
C盘碎片整理时“无法移动的文件”的处理
【转帖】VS2008+SQL2005开发环境搭建
【转帖】财务尽职调查资料收集总结
SQL2005开发版SSIS正常连接需要修改的地方
【未解决】制作可选择目录树的控件(替换使用参数进行递进选择)
【未解决】VS2008与Reporting Services结合生成的网站,速度超慢,何故?
新博开张
【已解决】尝试为文件 ......\App_Data\aspnetdb.mdf 附加自动命名的数据库,但失败...
SSRS表达式
原文地址:https://www.cnblogs.com/cnaspnet/p/1206263.html
最新文章
2016年总结_展望2017年
SpringBoot学习之Json数据交互
创建hbaseindexer出现 0 running
如何写复杂的SQL
乞丐版servlet容器第3篇
乞丐版servlet容器第1篇
ORA01034:ORACLE not available问题的解决方法
乞丐版servlet容器第2篇
Flink入门使用
My97DatePicker选择两个日期范围不超过30天的demo
热门文章
Problem of Uninstall Cloudera: Cannot Add Hdfs and Reported Cannot Find CDH's bigtopdetectjavahome
乞丐版servlet容器第4篇
【未解决】在数据源控件中“配置数据源”时,与具有架构特点的SQL数据库表产生冲突
【转帖】想和老婆一起做的事情
一个学习地址的收藏
【转帖】我最恐惧的事情是竞争力的丧失
【未解决】火狐浏览器与IE8的区别
【msdn】配置 ReportViewer 以进行远程处理
【未解决】Reporting Services报表在浏览器中的显示
【未解决】:VS2008配置数据源之要求安装SQL Server Express 2005才能正常工作
Copyright © 2011-2022 走看看