在下面的代码中,我导出excel从网格导出时,前导零被删除。我想保持前导零。请帮我解决问题。
HtmlForm form = new HtmlForm();
Response.Clear();
Response.Buffer = true;
Response.Charset = "";
Response.AddHeader("content-disposition", string.Format("attachment;filename={0}", "Supply/DemandReport.xls"));
Response.ContentType = "application/ms-excel";
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
gdSupplyorDemand.AllowPaging = false;
gdSupplyorDemand.HeaderStyle.ForeColor = System.Drawing.Color.Black;
form.Attributes["runat"] = "server";
form.Controls.Add(gdSupplyorDemand);
this.Controls.Add(form);
form.RenderControl(hw);
string style = @"<style> .textmode { mso-number-form at:\@;}</style>";
Response.Write(style);
Response.Output.Write(sw.ToString());
Response.Flush();
Response.End();
答案 0 :(得分:0)
在Excel中,数字单元格总是剥离前导零。一个技巧是使其成为字符串而不是数字。您可以使用"\t"
。
例如: -
int Value=00123
string newValue="\t"+value;
这应该有用......
答案 1 :(得分:0)