You need to enable JavaScript to run this app. VB.NET导出DataTable到Excel时解决加载GIF动画冻结问题
优惠活动
大模型
产品
解决方案
定价
更多

VB.NET导出DataTable到Excel时解决加载GIF动画冻结问题

功能开发说明
  • 开发语言为VB.NET,核心功能是将DataTable导出为Excel文件。
  • 由于导出流程耗时较长,为避免用户误认为程序无响应,计划在操作执行期间通过PictureLoading控件展示加载GIF动图作为提示。
已编写的实现代码
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
遇到的实际问题

运行上述代码时,加载GIF会出现冻结,无法正常播放动画,无法起到预期的加载提示作用。需要找到可行方法,在导出进程执行的等待期间,保持加载动图正常播放。


内容的提问来源于stack exchange,提问作者Marco

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.29 15:15:02