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
2 Replies
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Rahul PrasadPosted Aug 17, 2016, 9:04 PM
Karthik ElumalaiPosted Aug 17, 2016, 1:00 PM