VB杀Excel进程

<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




                
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值