我有一个导出到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();
答案 0 :(得分:2)
向下和脏,在开始时将值作为带有'
(单引号)的字符串发送。
答案 1 :(得分:0)
添加&#34; \ t&#34;在你的字符串之前它会使字符串显示在新选项卡中。