COMException(0x80010108 - RPC_E_DISCONNECTED)关闭Excel.Workbook时

Ste*_*ven 3 vb.net excel interop com-interop excel-interop

当我运行以下代码时,我得到以下异常:

''# NOTE: ExcelApp is a Private main form variable
Dim ReportBooks As Excel.Workbooks = ExcelApp.Workbooks
Dim ReportBook As Excel.Workbook = ReportBooks.Open(localFilename)
Dim ReportSheet As Excel.Worksheet = ReportBook.Sheets("Report")

''# Retreive data from sheet

ReleaseCOM(ReportSheet)
ReportBook.Close(True) ''# Error raised here
ReleaseCOM(ReportBook)
ReleaseCOM(ReportBooks)
Run Code Online (Sandbox Code Playgroud)
ERROR:
COMException was unhandled
The object invoked has disconnected from its clients.
(Exception from HRESULT: 0x80010108 (RPC_E_DISCONNECTED))
Run Code Online (Sandbox Code Playgroud)

注意:所有数据似乎都已正确检索.

请帮我诊断并克服这个错误.

Tod*_*ain 6

RPC_DISCONNECTED ...可怕的" 调用的对象已与其客户端断开连接. "问题.这有很多原因,看起来你已经涵盖了全局变量问题Excel..你能把第一个放在ReleaseCOM(ReportSheet)下面ReportBook(Close)然后运行吗?另外,看看这个.