I've worked on this and hope this will help you. Instead of using Excel COM you can simply go for this which saves system resources. Consider this example.... Dim myConnection As SqlConnection Dim myCommand As SqlDataAdapter ' Create a connection to the "pubs"
SQL database located on the local computer. myConnection = New SqlConnection("server=localhost; database=pubs;UID=;PWD=;") ' Connect to the SQL database using a SQL SELECT query to get all ' the data from the "Authors" table. myCommand = New SqlDataAdapter("SELECT
* FROM Authors", myConnection) ' Create and fill a DataSet. Dim ds As DataSet = New DataSet() myCommand.Fill(ds) ' now that you got the dataset, u use this to populate the temporary datagrid Response.Clear() Response.Charset = "" Response.ContentType = "application/vnd.ms-excel"
' set the content type Dim stringWrite As New System.IO.StringWriter() Dim htmlWrite As New System.Web.UI.HtmlTextWriter(stringWrite) Dim dg As New System.Web.UI.WebControls.DataGrid() dg.DataSource = ds.Tables(0) ' it is here where u need to assign ur datatable
dg.DataBind() dg.RenderControl(htmlWrite) Response.Write(stringWrite.ToString) Response.End() ' this will not have any refence to teh Excel object....hope u njoi it.. Cheers Srinivas
None
0 Points
10 Posts
Re: excel generation
Nov 21, 2003 12:35 AM|Y.Srinivas|LINK