I am exporting a gridview to Excel using
var Response = HttpContext.Current.Response;
string attachment = String.Format("attachment; filename=
{0}.xls", FileName.Replace(" ", string.Empty));
Response.ClearContent();
Response.AddHeader("content-disposition", attachment);
Response.ContentType = "application/ms-excel";
var sw = new StringWriter();
var htw = new HtmlTextWriter(sw);
gv.RenderControl(htw);
Response.Write(sw.ToString());
Response.End();
The string/file which Excel opens contains a table style element that
sets the background to black. I want that white instead. I tried
this at the top of the above snip to try and locate the html element:
for (int i = 0; i < gv.Controls.Count; i++)
{
var type = gv.Controls[i].GetType();
if (type == typeof(Table))
{
but never get a hit. Do I have to manipulate the html string myself,
find <table style..... and change the background value? (I dumped
the file and <table style ... is there)
I also tried typeOf(System.Web.UI.WebControls.ChildTable), the closest
thing I could find to table, but I get an error:
System.Web.UI.WebControls.ChildTable' is inaccessible due to its
protection level
Thanks.