vb.net调用excle,为什么下面代码执行完了,但进程里面依然有excle。exe
PrivateSubButton1_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesBu...
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
OpenFileDialog1.Filter = "Excle文件|*.xls;*.xlsx"
Dim ss
ss = OpenFileDialog1.ShowDialog()
If ss = 2 Then
Exit Sub
End If
TextBox1.Text = (OpenFileDialog1.FileName)
Dim xlApp As New Excel.Application()
' Dim xlBook As Excel.Workbook
'Dim xlSheet As Excel.Worksheet
Try
xlApp = CreateObject("Excel.Application")
' xlBook = xlApp.Workbooks().Add
'xlSheet = xlBook.Worksheets("sheet1")
xlApp.Workbooks.Open(OpenFileDialog1.FileName)
xlApp.Visible = False '设置EXCEL对象可见(或不可见)
For i = 1 To xlApp.Worksheets.Count '设定变量范围为i=1到 工作表集合的计数值
'If Worksheets(i).Name = "目录" Then '如果 <工作表>(i )的名称="目录" 则执行
' Exit For '退出for循环
'End If 'If判断过程结束
ListBox1.Items.Add(xlApp.Worksheets(i).Name)
ComboBox1.Items.Add(xlApp.Worksheets(i).Name)
'x = x & xlApp.Worksheets(i).Name
' MsgBox(x)
Next '下一个
'ComboBox1.Text = ComboBox1.Items(0)
xlApp.Workbooks.Close()
xlApp.Quit()
NAR(xlApp)
Catch ex As Exception
xlApp.Workbooks.Close()
xlApp.Quit()
xlApp = Nothing
MsgBox(ex)
End Try
'xlApp = Nothing
End Sub 展开
OpenFileDialog1.Filter = "Excle文件|*.xls;*.xlsx"
Dim ss
ss = OpenFileDialog1.ShowDialog()
If ss = 2 Then
Exit Sub
End If
TextBox1.Text = (OpenFileDialog1.FileName)
Dim xlApp As New Excel.Application()
' Dim xlBook As Excel.Workbook
'Dim xlSheet As Excel.Worksheet
Try
xlApp = CreateObject("Excel.Application")
' xlBook = xlApp.Workbooks().Add
'xlSheet = xlBook.Worksheets("sheet1")
xlApp.Workbooks.Open(OpenFileDialog1.FileName)
xlApp.Visible = False '设置EXCEL对象可见(或不可见)
For i = 1 To xlApp.Worksheets.Count '设定变量范围为i=1到 工作表集合的计数值
'If Worksheets(i).Name = "目录" Then '如果 <工作表>(i )的名称="目录" 则执行
' Exit For '退出for循环
'End If 'If判断过程结束
ListBox1.Items.Add(xlApp.Worksheets(i).Name)
ComboBox1.Items.Add(xlApp.Worksheets(i).Name)
'x = x & xlApp.Worksheets(i).Name
' MsgBox(x)
Next '下一个
'ComboBox1.Text = ComboBox1.Items(0)
xlApp.Workbooks.Close()
xlApp.Quit()
NAR(xlApp)
Catch ex As Exception
xlApp.Workbooks.Close()
xlApp.Quit()
xlApp = Nothing
MsgBox(ex)
End Try
'xlApp = Nothing
End Sub 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询