老师,用以下代码合并Excel数据后,删除源文件提示正在使用,该如何解决?谢谢!Dim dlg As New OpenFileDialog '定义一个新的OpenFileDialog
dlg.Filter = "Excel文件|*.xls;*.xlsx" '设置筛选器
If dlg.ShowDialog = DialogResult.Ok Then '如果用户单击了确定按钮
Dim ifo As New FileInfo(dlg.FileName)
If ifo.Extension <> ".xls" And ifo.Extension <> ".xlsx" Then
MessageBox.Show("选择的是非Excel格式文件,请重新选择!", "提示")
Return
End If
Dim sheetname As String
Dim App As New MSExcel.Application
Dim Wb As MSExcel.WorkBook = App.WorkBooks.Open(dlg.FileName)
sheetname = Wb.WorkSheets(1).Name & "$"
App.Quit
Dim mg As New Merger
mg.SourcePath = dlg.FileName
mg.Format = "excel" '指定格式
mg.SourceTableName = sheetname '指定要合并的表
mg.DataTableName = "员工花名册" '指定接收数据的表
mg.Merge() '开始合并
End If
此主题相关图片如下:微信截图_20230904121018.png