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%
}
}
查看全文
相关阅读:
P3_C17:设计对象的原则
【c++编程习惯】关于我自己
淘宝退货业务 活动图
UML绘图要点
P2_C4-7:初始阶段
P3_C8-11:细化阶段-基础迭代
P3_C14-16:面向对象设计
P3_C12-13:逻辑架构和包图
P1_C1-3:系统分析与设计概要
Chapter11 线程
原文地址:https://www.cnblogs.com/cnaspnet/p/1206263.html
最新文章
ShowVendDefaultDimension
Example of Fixed Asset Service Operations
AX2012 getDefaultDimensionFromLedgerDimension
AX2012SRS直接打印到文件
AX宏Macros运算
AX2009 C#客户端通过Web service批量审核工作流(三)
AX2009 C#客户端通过Web service批量审核工作流(二)
谈谈对协程的理解
Sicily1317-Sudoku-位运算暴搜
Sicily1099-Packing Passengers-拓展欧几里德算法
热门文章
AQL Subset Compiler:手把手教你如何写一个完整的编译器
Sicily1059-Exocenter of a Trian
爬山法、随机重启爬山法、模拟退火算法对八皇后问题和八数码问题的性能测试
Sicily1153-马的周游问题:启发式搜索
Sicily1151:魔板搜索及优化
Sicily1020-大数求余算法及优化
Pintos-斯坦福大学操作系统Project详解-Project1
学习系统分析与设计-序
ubuntu 各种软件安装配置
【基础复习】:序
Copyright © 2011-2022 走看看