[英]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();
}
}
}
CustomMarshal
和GetActiveObject()
的解釋可以在這里找到: No definition found for GetActiveObject from System.Runtime.InteropServices.Marshal C#
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.