这是导入一个execl表。导入后,我需要用一个新的excel来覆盖老的,就会出现被其它程序占用。
这个该如何解决呢?
Dim App As New MSExcel.Application
try
Dim Wb As MSExcel.Workbook = App.WorkBooks.Open("D:\盘库.xls")
Dim Ws As MSExcel.WorkSheet = Wb.WorkSheets(1)
Dim tsxx As WinForm.Label = e.Form.Controls("Label43")
tsxx.text = "正在导入******,请耐心等待!"
Tables("U8物料数量汇总表").StopRedraw()
'注意以下数组中列名称的顺序,必须和Excel表中的列顺序一致
Dim ra = ws.UsedRange
Dim nms() As String = {"物料编码","物料名称","总数量"}
'注意下面的循环变量从1开始,而不是从0开始,因为Excel表的第一行是标题
For n As Integer = 2 To ra.Rows.Count
Dim wlbm As String = ws.cells(n,1).Text
Dim wlmc As String = ws.cells(n,2).text
Dim zsl As String = ws.cells(n,3).text
If DataTables("U8物料数量汇总表").SQLFind("物料编码 = '" & wlbm & "' and 物料名称 = '" & wlmc & "'") Is Nothing Then '如果不存在同编号的计划表
Dim r As Row = Tables("U8物料数量汇总表").AddNew()
For m As Integer = 0 To nms.Length - 1
r(nms(m)) = ws.cells(n,m+1).Value
Next
End If
Next
Tables("U8物料数量汇总表").ResumeRedraw()
Tables("U8物料数量汇总表").save
DataTables("U8物料数量汇总表").LoadFilter = "状态 is null"
DataTables("U8物料数量汇总表").load
tsxx.text = "请导入盘库表"
msgbox("导入完成")
catch ex As exception
msgbox(ex.message)
app.quit
End try