Pages

Saturday, October 5, 2013

Convert Html page to Excell of Word file

Public Sub ExportData(ByVal DataToExport As String, ByVal FileName As String, ByVal mode As String)


HttpContext.Current.Response.ClearContent()
If mode.ToUpper() = "EXCEL" Then

Dim attachment As String = "attachment; filename=" & FileName & ".xls"

HttpContext.Current.Response.AddHeader("content-disposition", attachment)

HttpContext.Current.Response.ContentType = "application/vnd.ms-excel"

ElseIf mode.ToUpper() = "WORD" Then

Dim attachment As String = "attachment; filename=" & FileName & ".doc"

HttpContext.Current.Response.AddHeader("content-disposition", attachment)

HttpContext.Current.Response.ContentType = "application/ms-word"

End If


HttpContext.Current.Response.Write(DataToExport.ToString())

HttpContext.Current.Response.End()
End Sub

No comments:

Post a Comment