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%
}
}
查看全文
相关阅读:
反射API(二)
反射API(一)
session一二事
自定义session的存储机制
JavaScript 入门笔记
PHP引用赋值
九九乘法口诀表
PHP流程控制笔记
PHP函数总结 (七)
Linux程序编辑器习题汇总
原文地址:https://www.cnblogs.com/cnaspnet/p/1206263.html
最新文章
LeetCode 163. Missing Ranges (缺失的区间)$
LeetCode 162. Find Peak Element (找到峰值)
LeetCode 153. Find Minimum in Rotated Sorted Array (在旋转有序数组中找到最小值)
LeetCode 152. Maximum Product Subarray (最大乘积子数组)
LeetCode 122. Best Time to Buy and Sell Stock II (买卖股票的最好时机之二)
LeetCode 121. Best Time to Buy and Sell Stock (买卖股票的最好时机)
LeetCode 120. Triangle (三角形)
LeetCode 119. Pascal's Triangle II (杨辉三角之二)
LeetCode 118. Pascal's Triangle (杨辉三角)
12、判定表法
热门文章
11、因果图法
10、边界值
9、黑盒测试
8、V模型、W模型、H模型
7、瀑布模型、快速原型模型、螺旋模型
6.MySQL简介
5、Linux操作系统介绍
4、软件测试的基本介绍
3、CSS基本介绍
centos 7 源代码安装mysql5.6
Copyright © 2011-2022 走看看