111,126
社区成员
发帖
与我相关
我的任务
分享 Protected Sub btn_excel_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btn_excel.Click
Try
Response.Clear()
Response.Buffer = True
Response.Charset = "utf-8"
Response.AppendHeader("Content-Disposition", "attachment;filename=Customer.xls")
Response.ContentEncoding = System.Text.Encoding.GetEncoding("utf-8")
Response.ContentType = "application/ms-excel"
Me.EnableViewState = False
Dim StringWriter As New System.IO.StringWriter()
Dim htmlWriter As New System.Web.UI.HtmlTextWriter(StringWriter)
Dim i As Integer
Dim dt As DataTable = Nothing
dt = Session("resultlist")
If dt.Rows.Count > 5000 Then
Dim bindDataTable As New DataTable
Dim col As DataColumn = Nothing
col = New DataColumn("WorkOrderID")
bindDataTable.Columns.Add(col)
col = New DataColumn("CustomerID")
bindDataTable.Columns.Add(col)
col = New DataColumn("LocationID")
bindDataTable.Columns.Add(col)
col = New DataColumn("Gcc_Contact")
bindDataTable.Columns.Add(col)
col = New DataColumn("Description")
bindDataTable.Columns.Add(col)
col = New DataColumn("Scheduled_Completion")
bindDataTable.Columns.Add(col)
col = New DataColumn("Actual_Completion")
bindDataTable.Columns.Add(col)
col = New DataColumn("Received")
bindDataTable.Columns.Add(col)
col = New DataColumn("ClientNTE")
bindDataTable.Columns.Add(col)
col = New DataColumn("ProjectCode")
bindDataTable.Columns.Add(col)
For i = 0 To 4999
Dim dr As DataRow = bindDataTable.NewRow()
dr("WorkOrderID") = dt.Rows(i)("WorkOrderID")
dr("CustomerID") = dt.Rows(i)("CustomerID")
dr("LocationID") = dt.Rows(i)("LocationID")
dr("Gcc_Contact") = dt.Rows(i)("Gcc_Contact")
dr("Description") = dt.Rows(i)("Description")
dr("Scheduled_Completion") = dt.Rows(i)("Scheduled_Completion")
dr("Actual_Completion") = dt.Rows(i)("Actual_Completion")
dr("Received") = dt.Rows(i)("Received")
dr("ClientNTE") = dt.Rows(i)("ClientNTE")
dr("ProjectCode") = dt.Rows(i)("ProjectCode")
bindDataTable.Rows.Add(dr)
Next
Me.GridView1.AllowPaging = False
Me.GridView1.DataSource = bindDataTable
Else
Me.GridView1.AllowPaging = False
Me.GridView1.DataSource = dt
End If
Me.GridView1.DataBind()
setcustomerinfo(Me.GridView1)
Me.GridView1.Columns(8).Visible = False
Me.GridView1.RenderControl(htmlWriter)
Response.Write(StringWriter.ToString())
Response.Flush()
Response.End()
Catch ex As Exception
LogUtil.ErrorLog("new_customer_location_history.aspx", "Excel", ex.Message & vbCrLf & ex.StackTrace)
End Try
End Sub