对不起,如果这个问题不合适,那就是将一个表格从数据集复制到Excel工作表 的虚拟代码 对于这个问题?
如果是这样的话,复制一个完整的行怎么样会花费相同的时间或更快。
Private Sub btnExportoEcel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExportEcel.Click
Dim excelObj As New Microsoft.Office.Interop.Excel.Application
Dim WBk As Microsoft.Office.Interop.Excel.Workbook
Dim sht As Microsoft.Office.Interop.Excel.Worksheet
Dim pathOfxl As String
diagSave.ShowDialog()
pathOfxl = diagSave.FileName
excelObj = CreateObject("Excel.Application")
WBk = excelObj.Workbooks.Add
sht = WBk.ActiveSheet
sht.Activate()
With sht.Range("A1", "F1")
.Font.Bold = True
.Borders.Weight = 2
.ColumnWidth = 30
End With
sht.Cells(1, 1).value = "First Name"
sht.Cells(1, 2).value = "Last Name"
sht.Cells(1, 3).value = "Phone Number"
sht.Cells(1, 4).value = "Mobile Number"
sht.Cells(1, 5).value = "Email Address"
'Below is a user control which i created to show Visual Progressing
myProgressBar = New Progress'user control class
myProgressBar.pbMin = 0
myProgressBar.pbMax = contactView.Rows.Count
myProgressBar.setTitle = "Copy to Excel"
myProgressBar.Show()
' Here it starts copying CELLS one by one
For datarw = 1 To contactView.Rows.Count
myProgressBar.increasePbarValue()
For dataclm = 0 To 4
sht.Cells(datarw + 1, dataclm + 1).value = dataSet.Tables("Contact").Rows(datarw - 1).Item(dataclm + 1)
Next
Next
WBk.SaveAs(pathOfxl)
WBk.Saved = True
WBk.Close()
excelObj.Quit()
myProgressBar.Dispose()
myProgressBar = Nothing
excelObj = Nothing
WBk = Nothing
sht = Nothing
pathOfxl = Nothing
End Sub