C# 如何使用命令参数运行Interop.Excel.Application?

C# 如何使用命令参数运行Interop.Excel.Application?,c#,office-interop,office-addins,excel-interop,excel-addins,C#,Office Interop,Office Addins,Excel Interop,Excel Addins,我需要将参数传递给excel的新实例,然后通过加载项从新实例读取参数 我想使用此结构打开新的excel应用程序: new Microsoft.Office.Interop.Excel.Application() 是否有一种方法可以传递命令行参数,例如: string argument = "TestArgument"; new Microsoft.Office.Interop.Excel.Application(argument); 谢谢大家! 如果必须这样做(我建议尽可

我需要将参数传递给excel的新实例,然后通过加载项从新实例读取参数

我想使用此结构打开新的excel应用程序:

new Microsoft.Office.Interop.Excel.Application()
是否有一种方法可以传递命令行参数,例如:

string argument = "TestArgument";
new Microsoft.Office.Interop.Excel.Application(argument);
谢谢大家!

如果必须这样做(我建议尽可能快地从Interop运行),您可以 可以启动Excel应用程序,然后获取对它的引用

// start Excel with your command line arguments
var pathToExcel = @"C:\Program Files\Microsoft Office\root\Office16\excel.exe";
var commandLineArguments = "/whatever";
System.Diagnostics.Process.Start(pathToExcel, commandLineArguments);

// get a reference to it
Microsoft.Office.Interop.Excel.Application app = (Microsoft.Office.Interop.Excel.Application)
    System.Runtime.InteropServices.Marshal.GetActiveObject("Excel.Application");
Interop是如此邪恶,以至于我觉得回答这个问题几乎是不道德的。它打开了无尽痛苦的大门。如果可能的话,我建议使用类似与Excel文件交互的东西