<pre name="code" class="plain"> Dim before_time As Date = Now
Dim xlsWorkbook As Excel.Workbook '文档’
Dim xlssheet As Excel.Worksheet
open_excel.Filter = "Excel文件(*.xls)|*.xls|(*.xlsx)|*.xlsx"
If open_excel.ShowDialog() = DialogResult.OK Then
'获取选中的路径
Dim file_path As String = open_excel.FileName
xlsApp = CreateObject("Excel.Application")
xlsWorkbook = xlsApp.Workbooks.Open(file_path)
Dim tmpPro1 As New Process '定义一个进程
Dim procs1 As Process() = Process.GetProcessesByName("EXCEL") '将进程指向Excel ,这局必须写在打开excel之后
xlsApp.Range("A1").Select()
'xlssheet.Activate()
xlssheet = xlsApp.Sheets(1)
'获取当前记录行数
Dim rowcount As Integer = xlssheet.UsedRange.Rows.Count
'列数
Dim col As Integer = xlssheet.UsedRange.Columns.Count
'For i As Integer = 1 To rowcount - 1
For j As Integer = 0 To col
MsgBox(xlsApp.ActiveCell.Offset(1, j).Value)
Next
Dim end_time As Date = Now
For Each tmpPro1 In procs1 '遍历进程中该时间段的excel进程,并杀掉
If tmpPro1.StartTime >= before_time And tmpPro1.StartTime <= end_time Then
tmpPro1.Kill()
End If
Next
VB杀Excel进程
最新推荐文章于 2023-02-13 15:45:00 发布