leading 0s omitted when exporting to Excel

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

When I export the contents of a datagrid to excel, the leading 0s of the
first column are truncated. Is there a way to keep this from happening. I
am using the following code:


private void ExportToExcel()
{
Response.Clear();
Response.Buffer = true;
Response.ContentType = "application/vnd.ms-excel";
Response.Charset = "";
this.EnableViewState = false;
StringWriter tw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(tw);
reportGrid.Width = 800;
hw.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.Html);
//this.ClearControls(reportGrid);
reportGrid.RenderControl(hw);
hw.RenderEndTag();
Response.Write(tw.ToString());
Response.End();
}
 
Are you sure that they are omitted? If they are numbers, then Excel is
not going to display the leading 0's, but they are still there. Check the
file out in notepad, and make sure that the numbers are there.

Hope this helps.
 
Back
Top