VB.NET 子窗体导出Excel进度显示在父窗体ToolStripProgressBar上

来源:互联网 发布:网络信息的利与弊稿子 编辑:程序博客网 时间:2024/05/21 12:45
 '首先在父窗体调用子窗体,打开子窗体的时候             Dim f As New frmChild()            f.ParentProcessBar = Me.tsProgressBar1 ''ParentProcessBar 是在子窗体中定义的一个ToolStripProgressBar            f.MdiParent = Me            f.Show() '然后在子窗体类中添加            Public ParentProcessBar As New ToolStripProgressBar然后在子窗体中添加SUB    Private Sub ExportExcel(ByVal daTable As DataTable)        Me.ParentProcessBar.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.ParentProcessBar.Minimum = 1            Me.ParentProcessBar.Maximum = Table.Rows.Count + 1            Me.ParentProcessBar.Value = rowIndex        Next        With xlSheet            .Range(.Cells(1, 1), .Cells(1, colIndex)).Font.Bold = True        End With        xlApp.Visible = True        Me.ParentProcessBar.Visible = False    End Sub'然后 在子窗体Button时间中调用SUB即可
原创粉丝点击