asp.net Excel导出及数据格式化处理(摘)
来源:互联网 发布:淘宝运营有多累 编辑:程序博客网 时间:2024/05/21 12:46
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%
}
}
{
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%
}
}
- asp.net Excel导出及数据格式化处理(摘)
- Excel导出及数据格式化处理(摘)
- asp.net导出Excel数据
- ASP.net数据导出excel
- asp.net mvc 数据导出excel表及自excel表导入数据到相应表
- ASP.NET导出数据到Excel
- ASP.NET导出数据到Excel!
- ASP.NET导出数据到Excel
- ASP.NET导出数据到Excel
- ASP.NET导出数据到Excel
- ASP.NET导出数据到Excel
- ASP.NET导出数据到Excel
- ASP.NET 数据导出到Excel
- asp.net将数据导出成EXCEL
- ASP.NET 数据导出到Excel
- asp.net 导出数据到EXCEL
- asp.net 导出数据到Excel
- asp.net导出Excel格式数据方案
- rhel5/centos5下R8168网卡的安装
- VMware, ... eth0....failed - no link present check cable解决方法
- 关于幻灯片图片切换js的使用
- Android的AlertDialog详解
- 【题】统计一个Byte中的“1”的个数(转)
- asp.net Excel导出及数据格式化处理(摘)
- 指尖初体验之虚拟键盘
- 有点受不了,准备离职
- c 文件操作
- 原型模式代码示例
- 快速实现一个基于Jws的Webservice项目
- 【openstack】Quantum关于Subnet的操作(LinuxBridge)
- java swing窗体圆角
- JavaScript 指引