掲示板システム
ホーム
アクセス解析
カテゴリ
ログアウト
【VB.NET】Excel作成でプロセスが残ってしまう場合 (ID:116310)
名前
ホームページ(ブログ、Twitterなど)のURL (省略可)
本文
いつも参考にさせていただきています。 VisualBasic.NETでExcelファイルを操作するプログラムを作っています。 .NETのCOM連携機能の仕様だからか、マメにMarshal.ReleaseComObject()をしないとExcelのプロセスが残っていまうようなのです。もう少し簡単に書くことはできないでしょうか? 具体的には下記コードで、①だけならプロセスは残らないのですが、続けて②も記述すると、プロセスが残ってしまいます。当然、別変数で扱って、Marshal.ReleaseComObject()すれば大丈夫なんですが、コード量が半端じゃなくなってしまいますので。。。 Dim xlApp As Excel.Application Dim xlBooks As Excel.Workbooks Dim xlBook As Excel.Workbook Dim xlSheets As Object Dim xlSheet As Excel.Worksheet Dim xlCells As Object Dim xlCell As Object Dim xlVal As Object xlApp = CreateObject("Excel.Application") xlBooks = xlApp.Workbooks xlBook = xlBooks.Open("C:test.xls") xlSheets = xlBook.Worksheets xlSheet = xlSheets(1) xlCells = xlSheet.Cells ①------------------------- xlCell = xlCells(9, 18) xlVal = xlCell.Value xlVal = "2" --------------------------- ②-------------------------- xlCell = xlCells(10, 10) xlVal = xlCell.Value xlVal = "3" ---------------------------- System.Runtime.InteropServices.Marshal.ReleaseComObject(xlCell) System.Runtime.InteropServices.Marshal.ReleaseComObject(xlCells) System.Runtime.InteropServices.Marshal.ReleaseComObject(xlSheet) System.Runtime.InteropServices.Marshal.ReleaseComObject(xlSheets) System.Runtime.InteropServices.Marshal.ReleaseComObject(xlBook.Worksheets) System.Runtime.InteropServices.Marshal.ReleaseComObject(xlBook) System.Runtime.InteropServices.Marshal.ReleaseComObject(xlBooks)
←解決時は質問者本人がここをチェックしてください。
戻る
掲示板システム
Copyright 2020 Takeshi Okamoto All Rights Reserved.