【问题标题】:How to get the current open documents in Excel using C#?如何使用 C# 在 Excel 中获取当前打开的文档?
【发布时间】:2011-01-27 19:24:42
【问题描述】:

我只需要在当前打开的 Microsoft Excel 实例中获取当前打开的文档列表。

但我不知道 Excel 术语,不知道这些文档是否称为工作簿、工作表或窗口等。

任何想法

【问题讨论】:

    标签: c# .net excel interop automation


    【解决方案1】:

    找到它(link)

    //Excel Application Object
    Microsoft.Office.Interop.Excel.Application oExcelApp;
    
    this.Activate ( );
    
    //Get reference to Excel.Application from the ROT.
    oExcelApp = ( Microsoft.Office.Interop.Excel.Application ) System.Runtime.InteropServices.Marshal.GetActiveObject ( "Excel.Application" );
    
    //Display the name of the object.
    MessageBox.Show ( oExcelApp.ActiveWorkbook.FullName );
    
    //Release the reference.
    oExcelApp = null;
    

    【讨论】:

    • 很高兴你找到了它。您可以接受自己的答案(复选标记),它会从“未回答”列表中删除此问题。
    • 谢谢,在 SO 允许我这样做之前还有 1 天时间:O
    【解决方案2】:

    您正在寻找 Workbooks 属性。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多