Public Sub ExportDataSetToExcel(ByVal ds As DataSet, ByVal filename As String)
'--------Export Dataset To Excel---------------'
Dim attachment As String = "attachment; filename=" & filename & ".xls"
Response.ClearContent() Response.AddHeader("content-disposition",attachment)
Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
' create a string writer
Using sw As New StringWriter()
Using htw As New HtmlTextWriter(sw)
' instantiate a datagrid
Dim dg As New DataGrid()
dg.DataSource = ds.Tables(0)
dg.HeaderStyle.Font.Bold = True
dg.DataBind()
dg.RenderControl(htw)
Response.Write(sw.ToString())
Response.[End]()
End Using
End Using
End Sub
No comments:
Post a Comment