【发布时间】:2021-06-18 10:12:23
【问题描述】:
我正在运行代码以将数据表导出到 Excel。由于这需要一段时间,我不想混淆用户并显示图像
Dim _excel As New Microsoft.Office.Interop.Excel.Application
Dim wBook As Microsoft.Office.Interop.Excel.Workbook
Dim wSheet As Microsoft.Office.Interop.Excel.Worksheet
PictureLoading.Visible = True
wBook = _excel.Workbooks.Add()
wSheet = wBook.ActiveSheet()
Dim dt As System.Data.DataTable = GetTableForCompleteArchive()
Dim dc As System.Data.DataColumn
Dim dr As System.Data.DataRow
Dim colIndex As Integer = 0
Dim rowIndex As Integer = 0
PictureLoading.Refresh()
For Each dc In dt.Columns
colIndex += 1
_excel.Cells(1, colIndex) = dc.ColumnName
Next
PictureLoading.Refresh()
For Each dr In dt.Rows
rowIndex += 1
colIndex = 0
For Each dc In dt.Columns
colIndex += 1
_excel.Cells(rowIndex + 1, colIndex) = dr(dc.ColumnName)
Next
Next
PictureLoading.Refresh()
wSheet.Columns.AutoFit()
Dim strFileName As String = Application.StartupPath & "\Export.xlsx" '"C:\datatable.xlsx"
If System.IO.File.Exists(strFileName) Then
System.IO.File.Delete(strFileName)
End If
PictureLoading.Refresh()
wBook.SaveAs(strFileName)
wBook.Close()
_excel.Quit()
PictureLoading.Visible = False
问题是图像冻结并且没有动画。有没有办法在等待过程时让图像动画?
【问题讨论】:
-
一种解决方案是将您的 excel 处理移动到后台线程,以便您在 UI 线程上显示动画。
-
@Hursey 你能告诉我怎么做吗?
-
@Hursey 我和后台工作人员一起工作
标签: excel vb.net winforms datatable animated-gif