zoukankan      html  css  js  c++  java
  • 使用 Visual Studio .NET 客户端执行自动化功能后不退出 Office 应用程序 代码

    1.

    vb.net

    Imports Microsoft.Office.Interop
    Private Sub NAR(ByVal o As Object)
        Try
          System.Runtime.InteropServices.Marshal.ReleaseComObject(o)
        Catch
        Finally
          o 
    = Nothing
        End Try
      End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim oApp As New Excel.Application()
        Dim oBooks As Excel.Workbooks 
    = oApp.Workbooks
        Dim oBook As Excel.Workbook 
    = oBooks.Add
        Dim oSheet As Excel.Worksheet 
    = oApp.ActiveSheet

        NAR(oSheet)
        oBook.Close(False)
        NAR(oBook)
        NAR(oBooks)
        oApp.Quit()
        NAR(oApp)

        GC.Collect()

        Debug.WriteLine(
    "Sleeping")
        System.Threading.Thread.Sleep(
    5000)
        Debug.WriteLine(
    "End Excel")
    End Sub

    C#

    Code

       exBook.Close(DBNull.Value, DBNull.Value, DBNull.Value)
                exApp.Workbooks.Close()
                exApp.Quit()
                System.Runtime.InteropServices.Marshal.ReleaseComObject(exApp)
                System.Runtime.InteropServices.Marshal.ReleaseComObject(exSheet)
                System.Runtime.InteropServices.Marshal.ReleaseComObject(exBook)
                exApp = Nothing
                exBook = Nothing
                exSheet = Nothing
                GC.Collect()

     参考文章:http://support.microsoft.com/?id=317109

  • 相关阅读:
    Rabbit简单测试实例
    RabbitMQ-2 工作队列
    RabbitMQ-1 Helloword
    utmp
    导入wordpress数据库到mysql报错
    Tengine 反向代理状态检测
    阿里云服务器挖矿wipefs处理
    JbossMiner 挖矿蠕虫分析 (转载)
    centos6+nginx+php+mysql+memcached+wordpress
    php安装ZendGuardLoader扩展问题
  • 原文地址:https://www.cnblogs.com/ike_li/p/1288658.html
Copyright © 2011-2022 走看看