Export Dataset to Excel
Posted on 2007-04-05
I use the following script to export dataset to excel
Public Class DataSetToExcel
Public Shared Sub Convert(ByVal ds As DataSet, ByVal response As HttpResponse)
'first let's clean up the response.object
response.Charset = ""
'set the response mime type for excel
response.ContentType = "application/vnd.ms-excel"
'create a string writer
Dim stringWrite As New System.IO.StringWriter
'create an htmltextwriter which uses the stringwriter
Dim htmlWrite As New System.Web.UI.HtmlTextWriter(stringWrite)
'instantiate a datagrid
Dim dg As New DataGrid
'set the datagrid datasource to the dataset passed in
dg.DataSource = ds.Tables(0)
'bind the datagrid
'tell the datagrid to render itself to our htmltextwriter
'all that's left is to output the html
It has been working fine except now that I move the script to a new SharePoint server, it stops working. Instead of exporting the dataset to an excel, it displays the XML on the screen. Help.