开发者

Excel XLSTART problem with C#/.Net

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 XLSTA开发者_运维知识库RT are not read, it's as if the /automation command line switch has been run.

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


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

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

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.

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

How to use use late binding to get excel instance?

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);


Because it uses interop, it opens Excel as an automation server. It is the same thing as using the /automation switch. When Excel is opened that way, all automatically opened files and auto-run macros are disabled.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜