Public Sub GenExlReport(ByVal P_DataSet As Data.DataSet, ByRef P_refdatagrid As DataGrid, ByRef P_HttpResponse As Web.HttpResponse, ByRef P_Page As Page)
If P_DataSet Is Nothing Then P_HttpResponse.Write("Error in generation of Exl Report") : Exit Sub
Dim DSList As New Data.DataSet
Dim MyView As New Data.DataView
Dim stringWrite As New System.IO.StringWriter
Dim htmlWrite As New HtmlTextWriter(stringWrite)
Try
DSList = P_DataSet
MyView.Table = DSList.Tables(0)
With P_refdatagrid
.DataSource = MyView
.DataBind()
.Visible = True
End With
With P_HttpResponse
.Clear()
.AddHeader("content-disposition", "attachment;filename=FileName.xls")
.Charset = String.Empty
.Cache.SetCacheability(HttpCacheability.NoCache)
.ContentType = "application/vnd.xls"
End With
P_refdatagrid.RenderControl(htmlWrite)
P_HttpResponse.Write(stringWrite.ToString())
P_refdatagrid.Visible = False
P_HttpResponse.End()
Catch ex As Exception
P_HttpResponse.Write("Error in generation of Exl Report")
Finally
DSList.Dispose() : MyView.Dispose()
stringWrite.Dispose() : htmlWrite.Dispose()
End Try
End Sub
No comments:
Post a Comment