16,554
社区成员
发帖
与我相关
我的任务
分享
调用子窗体时,就不能使用Me.tsProgressBar1:可参考如下代码:
父窗体调用窗体时用:
dim childForm as new childForm
childForm.ParentProcessBar= me.tsProgressBar1 'ParentProcessBar是定义的一个ProgressBar类型变量
childForm.show()
在子窗体中执行sub时使用:
Public Sub ExportExcel(ByVal daTable As DataTable)
Me.ParentProcessBar.Visible = True
...
Me.ParentProcessBar.Value = rowIndex
...
...
end sub
Public Sub ExportExcel(ByVal daTable As DataTable)
Me.tsProgressBar1.Visible = True
Dim xlApp As New Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
Dim rowIndex, colIndex As Integer
rowIndex = 1
colIndex = 0
xlBook = xlApp.Workbooks().Add
xlSheet = xlBook.Worksheets("sheet1")
Dim Table As New DataTable
Table = daTable
'将所得到的表的列名,赋值给单元格
Dim Col As DataColumn
Dim col1 As DataColumn
Dim Row As DataRow
For Each Col In Table.Columns
colIndex = colIndex + 1
xlApp.Cells(1, colIndex) = Col.ColumnName
Next
'得到的表所有行(, 赋值给单元格)
For Each Row In Table.Rows
rowIndex = rowIndex + 1
colIndex = 0
For Each col1 In Table.Columns
colIndex = colIndex + 1
xlApp.Cells(rowIndex, colIndex) = Row(col1.ColumnName)
Next
Me.tsProgressBar1.Minimum = 1
Me.tsProgressBar1.Maximum = Table.Rows.Count + 1
Me.tsProgressBar1.Value = rowIndex
Next
With xlSheet
.Range(.Cells(1, 1), .Cells(1, colIndex)).Font.Bold = True
End With
xlApp.Visible = True
Me.tsProgressBar1.Visible = False
End Sub