prabhu p

prabhu p

  • 2k
  • 181
  • 99.1k

How to export data to excel using gembox.spreedsheet dll

Aug 16 2016 10:25 AM
I want to download excel with multipe sheet,I passing two datatable for two sheets table for sheet1 and table1 for sheet2, while i submit excel downloading no issuse while opening excel file iam getting dialog box with error 
 Error  occur when wps spreed sheet opening this file 
Make sure you are permitted to access file  
Make sure have enough space
 
I want to know wheather my code is coorect or not 
and function is below 
 
 
Public Sub ExportToSpreadsheet(ByVal table As DataTable, ByVal table1 As DataTable, ByVal name As String)
Try
Dim attachment As String = "attachment; filename=" & name & Format(CDate(Now), "_ddMMyyyy_hhmmss") & ".xls"
HttpContext.Current.Response.ClearContent()
HttpContext.Current.Response.AddHeader("content-disposition", attachment)
Response.Buffer = True
Response.Charset = ""
HttpContext.Current.Response.ContentType = "application/vnd.ms-excel"
HttpContext.Current.Response.Write(vbLf)
Dim ef As ExcelFile
ef = New ExcelFile()
Dim ws As ExcelWorksheet
ws = ef.Worksheets.Add("Summary")
Dim ws1 As ExcelWorksheet
ws1 = ef.Worksheets.Add("MissingData")
ws.InsertDataTable(table, "A1", True)
ws1.InsertDataTable(table1, "A1", True)
Dim MyMemoryStream As New MemoryStream()
ef.SaveXls(MyMemoryStream)
MyMemoryStream.WriteTo(Response.OutputStream)
Catch excp As Exception
Errors.WriteToErrorLogWithUserName(excp, "", Session("UserName").ToString())
End Try
End Sub
Please do need full to us 
 
 
 

Answers (2)