C#导出到excel前导零

C#导出到excel前导零,c#,C#,我有一个导出到excel的功能,但是,在导出到excel时,如何防止excel抑制前导零?我有下面的代码,适用于一种风格,但它不工作…任何想法 Response.Clear(); Response.Buffer = true; Response.AddHeader("content-disposition", "attachment;filename=GridViewExport.xls"); Response.Charset = ""; Res

我有一个导出到excel的功能,但是,在导出到excel时,如何防止excel抑制前导零?我有下面的代码,适用于一种风格,但它不工作…任何想法

    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();
Response.Clear();
Response.Buffer=true;
Response.AddHeader(“内容处置”,
“附件;文件名=GridViewExport.xls”);
响应。Charset=“”;
Response.ContentType=“application/vnd.ms excel”;
StringWriter sw=新的StringWriter();
HtmlTextWriter hw=新的HtmlTextWriter(sw);
对于(int i=0;i
向下并变脏,将值作为字符串发送,并在开始处使用
(单引号)。

在字符串前添加“\t”。它将使字符串看起来像是在一个新选项卡中。

您是以字符串还是int形式发送它?字符串样式=@“。text{mso number format:\@;}”;我试过了,但单引号出现在excel表格上?谢谢,先生。一开始只有一个报价。