2013-11-20 117 views
4

我有一個導出爲ex​​cel函數,但是,如何在導出爲ex​​cel時抑制前導零的excel?我有下面的代碼適用於風格,但它不工作......任何想法?C#導出爲ex​​cel前導零

Response.Clear(); 
    Response.Buffer = true; 
    Response.AddHeader("content-disposition", 
    "attachment;filename=GridViewExport.xls"); 
    Response.Charset = ""; 
    Response.ContentType = "application/vnd.ms-excel"; 
    StringWriter sw = new StringWriter(); 
    HtmlTextWriter hw = new HtmlTextWriter(sw); 

    for (int i = 0; i < GridView1.Rows.Count; i++) 
    { 
     //Apply text style to each Row 
     GridView1.Rows[i].Attributes.Add("class", "textmode"); 
    } 
    GridView1.RenderControl(hw); 

    //style to format numbers to string 
    string style = @"<style> .text { mso-number-format:\@; } </style>"; 
    Response.Write(style); 
    Response.Output.Write(sw.ToString()); 
    Response.Flush(); 
    Response.End(); 
+0

你發送它作爲一個字符串或int? –

+0

string style = @「」; – user406151

回答

2

降濁,送價值在開始用'(單引號)的字符串。

+0

我試過,但單引號出現在Excel表單上? – user406151

+0

謝謝先生。在開始時單引號做了它。 – Terrance

0

在字符串前添加「\ t」。它會使字符串看起來在一個新的標籤中。