I am using the code below to export a datagrid to excel which works fine except for one thing. I have a Template column which contains a £ sign like this...Totals (£).
When the user selects the option to open the £ sign has this
Total (£)
need help to remove the A above which appears when the user opens the spreadsheet.
akshay144
Member
77 Points
89 Posts
problem with exporting to excel
Apr 11, 2006 04:13 PM|LINK
I am using the code below to export a datagrid to excel which works fine except for one thing. I have a Template column which contains a £ sign like this...Totals (£).
When the user selects the option to open the £ sign has this
Total (£)
need help to remove the A above which appears when the user opens the spreadsheet.
CODE:-
private void btn_export_Click(object sender, System.EventArgs e)
{
//export to excel
Response.Clear();
Response.Buffer= true;
Response.ContentType = "application/vnd.ms-excel";
Response.Charset = "";
this.EnableViewState = false;
System.IO.StringWriter oStringWriter = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
this.ClearControls(this.dgrd_display_MasterChangeListWIP);
this.dgrd_display_MasterChangeListWIP.RenderControl(oHtmlTextWriter);
Response.Write(oStringWriter.ToString());
Response.End();
}
private void ClearControls(Control control)
{
for (int i=control.Controls.Count -1; i>=0; i--)
{
ClearControls(control.Controls[i]);
}
if (!(control is TableCell))
{
if (control.GetType().GetProperty("SelectedItem") != null)
{
LiteralControl literal = new LiteralControl();
control.Parent.Controls.Add(literal);
try
{
literal.Text = (string)control.GetType().GetProperty("SelectedItem").GetValue(control,null);
}
catch
{
}
control.Parent.Controls.Remove(control);
}
else
if (control.GetType().GetProperty("Text") != null)
{
LiteralControl literal = new LiteralControl();
control.Parent.Controls.Add(literal);
literal.Text = (string)control.GetType().GetProperty("Text").GetValue(control,null);
control.Parent.Controls.Remove(control);
}
}
return;
}