prabhu p

prabhu p

  • NA
  • 181
  • 114.5k

How to export two datatables to excel

Nov 14 2016 6:28 AM
I have 2 datatable, from that I need Export to excel in single
sheet, I need output as like this but iam getting only one data table that lastly bind
 
----------------
Stockist not present in master distributor(title)
Stockistcode(Columnheader)
 
---
 
-----
 
----
 
linr break
 
List of CompanyFF User Id Not Present(title)
 Userid (Columnheader)
------
--------
--------
-------
------- 
My code
 
---------
Public Sub ExportToSpreadsheett(ByVal table As DataTable, ByVal table1 As DataTable, ByVal name As String, ByVal strReadString As String)
Try
If table.Rows.Count > 0 Then
Dim attachment As String = "attachment; filename=" & name & Format(CDate(Now), " ddMMyyyy_hhmmss") & ".xls"
HttpContext.Current.Response.ClearContent()
HttpContext.Current.Response.AddHeader("content-disposition", attachment)
HttpContext.Current.Response.ContentType = "application/vnd.ms-excel"
Dim userrtype As Integer
userrtype = CType(HttpContext.Current.Session("UserType"), Integer)
' HttpContext.Current.Response.Write("
")
HttpContext.Current.Response.Write("
")
HttpContext.Current.Response.Write(strReadString)
HttpContext.Current.Response.Write("
")
HttpContext.Current.Response.Write("Stockist not present in master distributor : ")
HttpContext.Current.Response.Write(vbLf)
Label1.Text = strReadString.ToString()
Dim GridView1 As New GridView()
GridView1.DataSource = table
GridView1.AllowPaging = False
GridView1.DataBind()
HttpContext.Current.Response.Write("
")
HttpContext.Current.Response.Write("
")
HttpContext.Current.Response.Write(" List of CompanyFF User Id Not Present ")
HttpContext.Current.Response.Write(vbLf)
Dim GRidView2 As New GridView()
GridView1.DataSource = table1
GridView1.AllowPaging = False
'GRidView2.DataBind()
GridView1.DataBind()
Dim sw As New StringWriter()
Dim hw As New HtmlTextWriter(sw)
'Change the Header Row back to white color
GridView1.HeaderRow.Style.Add("background-color", "#FFFFFF")
GridView1.HeaderStyle.Font.Bold = True
'Apply style to Individual Cells
For i As Integer = 0 To table.Columns.Count - 1
GridView1.HeaderRow.Cells(i).Style.Add("background-color", "#C2D69B")
Next
GridView1.RenderControl(hw)
Response.Output.Write(sw.ToString())
HttpContext.Current.Response.Flush()
HttpContext.Current.Response.SuppressContent = True
HttpContext.Current.ApplicationInstance.CompleteRequest()
'HttpContext.Current.ApplicationInstance.CompleteRequest()
Else
DisplayAlert("No Records Found!")
End If
Catch excp As Exception
Errors.WriteToErrorLogWithUserName(excp, "", Session("UserName").ToString())
End Try
End Sub
 
Please do need full to me  
 

Answers (2)