borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2010 Andrea Tincaniborder

AndreaVB | Forum | News | Downloads | Register | Help | Member List | Statistics | Search | PM | Profile

Print This Topic
Next Topic (Internet Programming EBooks FREE Wireless LAN) New Topic New Poll Post Reply
AndreaVB Forum : ASP.Net : ASP.NET DATAGRID EXPORT INTO EXCEL
Poster Message
ASPNewb
Level: Trainee

Registered: 07-08-2006
Posts: 1

Ads by Lake Quincy Media
icon 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!!!!!

07-08-2006 at 01:25 AM
View Profile Send Email to User Show All Posts | Quote Reply
CikaPero
Level: Trainee

Registered: 14-04-2010
Posts: 1
icon Re: ASP.NET DATAGRID EXPORT INTO EXCEL

Hi, you can easily convert DataGrid to Excel with GemBox.Spreadsheet Excel VB.NET library.

Here is a code snippet how to do it in your ASP.NET Excel app:
' Get DataTable that DataGrid is bound to.
Dim dataTable = DirectCast(dataGrid.DataSource, DataTable)

' Create new ExcelFile.
Dim ef = New ExcelFile()
' Add new worksheet to the file.
Dim ws = ef.Worksheets.Add(dataTable.TableName)
' Insert the data from DataTable to the worksheet starting at cell "A1".
ws.InsertDataTable(dataTable, "A1", True)

' Stream file to browser.
Response.Clear()
Response.ContentType = "application/vnd.ms-excel"
Response.AddHeader("Content-Disposition", "attachment; filename=Employee.xls")
ef.SaveXls(Response.OutputStream)
Response.End()

For live web demo see:
http://www.gemboxsoftware.com/WebDemo/Index.aspx

14-04-2010 at 08:29 AM
View Profile Send Email to User Show All Posts | Quote Reply
jasonrle0332
Level: Protégé

Registered: 23-08-2010
Posts: 7
icon Re: ASP.NET DATAGRID EXPORT INTO EXCEL

Recommend another Excel VB.NET Component: Spire.XLS for .NET

____________________________
jason rle

09-12-2010 at 03:23 AM
View Profile Send Email to User Show All Posts | Quote Reply
AndreaVB Forum : ASP.Net : ASP.NET DATAGRID EXPORT INTO EXCEL
Next Topic (Internet Programming EBooks FREE Wireless LAN) New Topic New Poll Post Reply
Surf To:


Not Logged In? Username: Password: Lost your password?
Partners: Download Actual Software | Free Software Download
borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2010 Andrea Tincaniborder