Excel中XLSTART问题,C#/。NET问题、Excel、XLSTART、NET

2023-09-05 23:34:33 作者:一身懵逼正气

我有一个C#应用程序(.NET 1.1),并使用Excel互操作显示一些reoprts。事实证明,打开一个Excel工作簿时,在XLSTART文件都看不懂,它好像/自动命令行开关已运行。

I have a C# application (.Net 1.1) and use excel interop to display some reoprts. It turns out that when opening an excel workbook the files in XLSTART are not read, it's as if the /automation command line switch has been run.

有没有什么办法,使XLSTART启动从C#的XLS表的时候?

Is there any way to enable XLSTART when launching an XLS sheet from C#?

推荐答案

此行​​为是设计使然。您可以加载加载项中的XLStart文件夹自己所描述的微软:

This behavior is by design. You can load the add-ins in the XLSTART folder yourself as described by Microsoft:

加载项在Excel中使用CreateObject命令时没有加载

Add-ins do not load when using the CreateObject command in Excel

你有另一种选择是使用启动Excel 的Process.Start ,然后从运行的实例通过调用自动化对象的 AccessibleObjectFromWindow 的功能。

Another option that you have is to start Excel using Process.Start and then an automation object from the running instance by calling the AccessibleObjectFromWindow function.

样品code如何做到这一点在C#或VB可以在一个相关的问题中找到:

Sample code how to do this in C# or VB can be found in a related question:

How使用使用后期绑定,以获得卓越的实例?

How to use use late binding to get excel instance?

请注意,您不必使用在给出的例子后期绑定。修改这样的样品应该给你一个强类型的 Excel.Application 目标:

Please note that you don't have to use late binding as in the example given. Modifying the sample like this should give you a strongly-typed Excel.Application object:

Excel.Application xlApp = ptr.GetType().InvokeMember("Application",
    BindingFlags.GetProperty, null, ptr, null);