首页 > 其他 > 详细

excel设置文本格式

时间:2014-05-04 20:38:35      阅读:620      评论:0      收藏:0      [点我收藏+]

public void ToExcel(System.Web.UI.Control ctl, string FileName)
bubuko.com,布布扣        
{
bubuko.com,布布扣            HttpContext.Current.Response.Charset 
= "UTF-8";
bubuko.com,布布扣            HttpContext.Current.Response.ContentEncoding 
= System.Text.Encoding.Default;
bubuko.com,布布扣            HttpContext.Current.Response.ContentType 
= "application/ms-excel";
bubuko.com,布布扣            HttpContext.Current.Response.AppendHeader(
"Content-Disposition""attachment;filename=" + "" + FileName + ".xls");
bubuko.com,布布扣            ctl.Page.EnableViewState 
= false;
bubuko.com,布布扣            System.IO.StringWriter tw 
= new System.IO.StringWriter();
bubuko.com,布布扣            HtmlTextWriter hw 
= new HtmlTextWriter(tw);
bubuko.com,布布扣            ctl.RenderControl(hw);
bubuko.com,布布扣            HttpContext.Current.Response.Write(tw.ToString());
bubuko.com,布布扣            HttpContext.Current.Response.End();
bubuko.com,布布扣        }

bubuko.com,布布扣        
public override void VerifyRenderingInServerForm(Control control)
bubuko.com,布布扣        
{
bubuko.com,布布扣            
//base.VerifyRenderingInServerForm(control);
bubuko.com,布布扣
        }

bubuko.com,布布扣        
protected void myGridView_RowDataBound(object sender, GridViewRowEventArgs e)
bubuko.com,布布扣        
{
bubuko.com,布布扣            
if (e.Row.RowType == DataControlRowType.DataRow)
bubuko.com,布布扣            
{
bubuko.com,布布扣                
//e.Row.Cells[0].Attributes.Add("style", "vnd.ms-excel.numberformat:@");//这里是将要导出到execl里的第一列格式化为字符类型。
bubuko.com,布布扣                
//e.Row.Cells[3].Attributes.Add("style", "vnd.ms-excel.numberformat:¥#,###.00");//这里是格式化为货币类型。
bubuko.com,布布扣
                e.Row.Cells[4].Attributes.Add("style""vnd.ms-excel.numberformat:@");
bubuko.com,布布扣                
//1) 文本:vnd.ms-excel.numberformat:@
bubuko.com,布布扣                
//2) 日期:vnd.ms-excel.numberformat:yyyy/mm/dd
bubuko.com,布布扣                
//3) 数字:vnd.ms-excel.numberformat:#,##0.00
bubuko.com,布布扣                
//4) 货币:vnd.ms-excel.numberformat:¥#,##0.00
bubuko.com,布布扣                
//5) 百分比:vnd.ms-excel.numberformat: #0.00%
bubuko.com,布布扣
            }

bubuko.com,布布扣        }

excel设置文本格式,布布扣,bubuko.com

excel设置文本格式

原文:http://www.cnblogs.com/kevin-2013/p/3706175.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!