如何在导出到Excel工作表时格式化网格列
嗨每一个,
我在网格上填写一些日期(来自数据库),并导出到excel。导出到excel后,显示值07896542如7896542,即左侧零修剪。请帮帮我,如何在导出到excel时格式化excel列。 请参阅以下代码。
提前致谢。
if(Excel ==YES)
{
System.IO.StringWriter tw = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter(tw);
DataGrid dgGrid = new DataGrid();
dgGrid = new DataGrid();
dgGrid.DataSource = dtinvoice;
dgGrid.HeaderStyle.Font.Bold = false;
dgGrid。 DataBind();
dgGrid.RenderControl(hw);
Response.AddHeader(Content-Disposition,attachment; filename = Executivereport.xls);
Response.ContentType =application / vnd.ms-excel; charset = utf-8;
Response.ContentEncodi ng = System.Text.Encoding.Unicode;
Response.BinaryWrite(System.Text.Encoding.Unicode.GetPreamble());
this.EnableViewState = false;
Response.Write(tw.ToString());
Response.End();
}
Hi Every one,
I am filling Grid with some date(from database),and exporting into excel.After exporting in to excel, the value 07896542 shown as 7896542 i.e. left side zero trimming. Please help me, how can I format excel column while exporting to excel. see the following code.
Thanks in advance.
if (Excel == "YES")
{
System.IO.StringWriter tw = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter(tw);
DataGrid dgGrid = new DataGrid();
dgGrid = new DataGrid();
dgGrid.DataSource = dtinvoice;
dgGrid.HeaderStyle.Font.Bold = false;
dgGrid.DataBind();
dgGrid.RenderControl(hw);
Response.AddHeader("Content-Disposition", "attachment;filename=Executivereport.xls");
Response.ContentType = "application/vnd.ms-excel ;charset=utf-8";
Response.ContentEncoding = System.Text.Encoding.Unicode;
Response.BinaryWrite(System.Text.Encoding.Unicode.GetPreamble());
this.EnableViewState = false;
Response.Write(tw.ToString());
Response.End();
}
您是否尝试使用单引号为您的值添加前缀?喜欢这样...
'07896542
如果这不起作用,那么试着包装你的价值在引号中并在它前面放置一个等号。像这样...
=07896542
Have you tried to prefix your value with a single quote? Like so...
'07896542
If this doesn't work then try wrapping your value in quotes and placing an equal sign in front of it. Like so...
="07896542"