Reputation: 11
I am trying to export just a table that is contained on my page. I have some filters above it but when exporting, all the text and filters are copied into this file.
This is the code:
tableCreateOrders a = new tableCreateOrders(dtReportColumns, 2, 10);
divResult.Controls.Add(a.displayTable());
Response.ContentType = "application/ms-excel";
Response.AddHeader("content-disposition", "attachment; filename=orders.xls");
Response.Write(a.displayTable());
a.displayTable()
is the object containing the table, but the filters are defined on the .aspx so there is no way the command take it. Is there anything I am doing wrong? I'll really appreciate any suggestion.
Upvotes: 1
Views: 127
Reputation: 1127
This is what you need. Remember to ClearContent before and End after.
Response.ClearContent();
Response.ContentType = "application/ms-excel";
Response.AddHeader("content-disposition", "attachment; filename=orders.xls");
Response.Write(a.DisplayTable());
Response.End();
Upvotes: 2