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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top