我使用Microsoft.Office.Interop.Excel
在c#中工作。
我有一个用于打开excel工作簿的函数。用户(或应用程序)可以关闭此工作簿。我的问题是我无法重新打开此工作簿。
Excel.Workbook Workbook;
private void OpenWorkbook(Excel.Application exApp)
{
// Check if a workbook has been opened
if (WorkBook != null)
{
// Create a workbook
WorkBook = exApp.Workbooks.Add();
}
else
{
// Add workbook to excel application
WorkBook = exApp.Workbooks.Add(WorkBook);
/*
=> this part doesn't work
Excel has been quit by user and I have a error : DisconnectedContext
*/
}
}
如何重新连接或重新创建工作簿?
答案 0 :(得分:0)
我想你错过了object Missing = System.Reflection.Missing.Value;
。
请尝试使用此示例:http://pastebin.com/xqhu9eCK