繁体   English   中英

如何在 c# 中获取当前 excel 文件名

[英]How do I get the current excel filename in c#

我正在编写一个应该跨多个 excel 文档模板工作的 VTSO 应用程序。 我希望加载项检查文档并尝试访问用户正在使用的 select,但是我不知道如何使用 VTSO 在 c# 中获取当前文件名

试试这个例子:

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#

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM