salve a tutti
sto sviluppando un progetto in Asp.net e C# e ho bisogno di creare un foglio Excel con i dati del mio database.
Sono riuscito a farlo in questo modo
protected void BtnExport_Click(object sender, ImageClickEventArgs e)
{
#region "Estrazione Nome File"
string filename = "Export";
#endregion
Response.Clear();
Response.AddHeader("content-disposition", "attachment;filename="+ filename +".xls");
Response.Charset = "";
Response.ContentType = "application/vnd.xls";
#region "Estrazione Dati Grid Contratti"
System.IO.StringWriter stringWrite = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
GridView dg = new GridView();
dg = GridViewSheetContratti;
dg.AllowSorting = false;
dg.AllowPaging = false;
dg.DataBind();
dg.RenderControl(htmlWrite);
Response.Write(stringWrite.ToString());
#endregion
#region "Estrazione Dati Grid Attività"
System.IO.StringWriter stringWriteAtt = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWriteAtt = new HtmlTextWriter(stringWriteAtt);
GridView dgAtt = new GridView();
dgAtt = GridViewSheetAttivita;
dgAtt.AllowSorting = false;
dgAtt.AllowPaging = false;
dgAtt.DataBind();
dgAtt.RenderControl(htmlWriteAtt);
Response.Write(stringWriteAtt.ToString());
#endregion
Response.End();
}
public override void VerifyRenderingInServerForm(Control control)
{
}
solo che il secondo blocco di informazioni (#region "Estrazione Dati Grid Attività") vorrei averlo sullo stesso file ma in un altro worksheet. è possibile con il codice strutturato in questo modo?
Spero di essere stato abbastanza chiaro
Alex