ASPNewb Level: Trainee
 Registered: 07-08-2006 Posts: 1
|
ASP.NET DATAGRID EXPORT INTO EXCEL
Currently i have the codes for exporting data in a datagrid into Microsoft Excel spreadsheet. The codes are placed inside a button event. The codes are : -
dgData.HeaderStyle.ForeColor = dgData.HeaderStyle.ForeColor.Black
Response.Clear()
Response.AddHeader("content-disposition", "attatchment;filename=filename.xls")
Response.Charset = ""
Response.Cache.SetCacheability(HttpCacheability.NoCache)
Response.ContentType = "application/vnd.xls"
Dim stringWrite As System.IO.StringWriter = New System.IO.StringWriter
Dim htmlwrite As System.Web.UI.HtmlTextWriter = New HtmlTextWriter(stringWrite)
dgData.RenderControl(htmlwrite)
Response.Write(stringWrite.ToString)
Response.End()
Currently what it does is it creates a new filename.xls everytime a user clicks on the export button. What i hope that could be done is that there can be a templated excel spreadsheet stored in the server and everytime a user clicks on the export button, they will download the templated excel spreadsheet together with the data aligned nicely according to the template.
Basically to achieve this, i will need to know if it is possible to :-
1. Is there a way to export the data in the datagrid into the excel spreadsheet and specify which cell the data should start the flow. (For example, the datagrid has "Title" as the start of all the columns - at the top right hand cell of the datagrid - and when it is exported into the excel, "Title" would appear at cell A1 of the excel spreadsheet. Is it possible to let the "Title" appear at cell C3?)
2. Is there a way to command the computer to use a templated excel spreadsheet stored in the server instead of always creating a new filename.xls?
MANY THANKS!!!!!
|