重新打开工作簿

时间:2017-01-23 10:48:55

标签: c# excel

我使用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
        */

    }
}

如何重新连接或重新创建工作簿?

1 个答案:

答案 0 :(得分:0)

我想你错过了object Missing = System.Reflection.Missing.Value;。 请尝试使用此示例:http://pastebin.com/xqhu9eCK