【问题标题】:How do I get the current excel filename in c#如何在c#中获取当前的excel文件名
【发布时间】:2021-10-05 23:29:53
【问题描述】:

我正在编写一个可以跨多个 Excel 文档模板工作的 VTSO 应用程序。我希望插件检查文档并尝试选择用户正在使用的文档,但是我无法弄清楚如何使用 VTSO 在 c# 中获取当前文件名

【问题讨论】:

    标签: c# excel


    【解决方案1】:

    试试这个例子:

    using System;
    using Excel = Microsoft.Office.Interop.Excel;
    
    namespace Foo
    {
        class Program
        {
            static void Main(string[] args)
            {
                var excelApplication = (Excel.Application)CustomMarshal.GetActiveObject("Excel.Application");
                var currentWorkbook = excelApplication.ActiveWorkbook;
                Console.WriteLine("Current active Excel Workbook: " + currentWorkbook.Name); // or FullName to get full path to opened file
                Console.ReadKey();
            }
        }
    }
    

    CustomMarshalGetActiveObject() 的解释可以在这里找到: No definition found for GetActiveObject from System.Runtime.InteropServices.Marshal C#

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-27
      • 1970-01-01
      相关资源
      最近更新 更多