but i already have my excel export working in standard fromat which i cannot change
Then I think you can do this trick:
1)In the Page_Load event handler,please dynamically generate a GridView:
if(!IsPostBack){GridView gv = new GridView(); gv.DataSource=yourDataTable;gv.DataBind();}
2)And then use the codes I've told you above to export to a whole excel file:
Response.Clear();
Response.AddHeader("content-disposition", "attachment;
filename=FileName.xls");
Response.Charset = "";
// If you want the option to open the Excel file without saving than
// comment out the line below
// Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.ContentType = "application/vnd.xls";
System.IO.StringWriter stringWrite = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite =
new HtmlTextWriter(stringWrite);
GridView1.RenderControl(htmlWrite);
Response.Write(stringWrite.ToString());
Response.End();
public override void VerifyRenderingInServerForm(Control control)
{
// Confirms that an HtmlForm control is rendered for the specified ASP.NET server control at run time.
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: Looping thorough a query and storing the row values in a Dictonary or someother object
May 07, 2012 01:19 AM|LINK
Then I think you can do this trick:
1)In the Page_Load event handler,please dynamically generate a GridView:
2)And then use the codes I've told you above to export to a whole excel file:
Response.Clear(); Response.AddHeader("content-disposition", "attachment; filename=FileName.xls"); Response.Charset = ""; // If you want the option to open the Excel file without saving than // comment out the line below // Response.Cache.SetCacheability(HttpCacheability.NoCache); Response.ContentType = "application/vnd.xls"; System.IO.StringWriter stringWrite = new System.IO.StringWriter(); System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite); GridView1.RenderControl(htmlWrite); Response.Write(stringWrite.ToString()); Response.End();public override void VerifyRenderingInServerForm(Control control)
{
// Confirms that an HtmlForm control is rendered for the
specified ASP.NET server control at run time.
}