|
楼主 |
发表于 2014-8-31 18:53
|
显示全部楼层
红色代码处很耗时,WCF服务的DataTable 读取很快,但写到excel表中很慢,每个单元格逐个写,不能一次性写入。
Dim client As ExcelWorkbook1.ServiceReference.ReportServiceClient = New ReportServiceClient()
' 使用 "client" 变量在服务上调用操作。
Dim Dbh As String = Globals.ThisWorkbook.Sheets("报表").Cells(1, 4).Text
Dim myds As System.Data.DataTable
client.Open()
If RadioButton1.Checked = 1 Then myds = client.GetReporData(Dbh, TextBox1.Text, TextBox2.Text, "1") Else myds = client.GetReporData(Dbh, TextBox1.Text, TextBox2.Text, "2")
client.Close()
'Globals.ThisWorkbook.Worksheets("sheet3").Range("a1") = myds.Rows.Count()
'Globals.ThisWorkbook.Worksheets("sheet3").Range("a2") = myds.TableName
Dim r As Integer = myds.Rows.Count()
Dim c As Integer = myds.Columns.Count()
If r > 0 And c > 0 Then
With Globals.ThisWorkbook.Sheets("qtbb")
Dim z As Integer = .UsedRange.Rows.Count
If z > 2 Then
If .AutoFilterMode Then
.Range("A2:AE2").AutoFilter()
.Range("A2:AE2").AutoFilter()
Else
.Range("A2:AE2").AutoFilter()
End If
.Rows("3:" & z & "").Delete()
End If
Dim j, k As Integer
For j = 0 To r - 1 Step 1
For k = 0 To c - 1 Step 1
If j = 0 Then
.Cells(2, k + 1) = myds.Columns(k).ColumnName
.Cells(3, k + 1) = myds.Rows(j)(k)
Else
.Cells(j + 3, k + 1) = myds.Rows(j)(k)
End If
Next
Globals.ThisWorkbook.Application.StatusBar = "下载中..." & j & "/" & r - 1
Next
End With
End If
myds.Clear() |
|