Excel e Asp.net

venerdì 25 agosto 2006 - 16.30

Irnei Profilo | Newbie

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

GvnnRules Profilo | Senior Member

Purtroppo credo che non ci sia un sistema da HTML (sono pronto a smentite ), una soluzione potrebbe essere produrre un file xml ... nel formato che excel interpreta, ti allego un export di statistiche, studiatelo e buon lavoro

Peace
Gvnn

http://www.gvnn.it
http://www.sqlwebarchitect.org
http://blogs.dotnethell.it/gvnn/
Partecipa anche tu! Registrati!
Hai bisogno di aiuto ?
Perchè non ti registri subito?

Dopo esserti registrato potrai chiedere
aiuto sul nostro Forum oppure aiutare gli altri

Consulta le Stanze disponibili.

Registrati ora !
Copyright © dotNetHell.it 2002-2024
Running on Windows Server 2008 R2 Standard, SQL Server 2012 & ASP.NET 3.5