Excel-DNA / ExcelDna

Excel-DNA - Free and easy .NET for Excel. This repository contains the core Excel-DNA library.
https://excel-dna.net
zlib License
1.28k stars 274 forks source link

ProgId/Guid for Custom Task Pane Helper #373

Open p0n3 opened 3 years ago

p0n3 commented 3 years ago

Problem There is no easy way to set ProgId/Guid for a Custom Task Pane Helper component (ExcelCustomTaskPaneAddIn), which might cause a problem in restricted environments.

Details ExcelCustomTaskPaneAddIn is an internal class and the instance is being created in the GetCTPFactory method inside CustomTaskPaneFactory:

// Register and create addin
_addin = new ExcelCustomTaskPaneAddIn { DnaLibrary = DnaLibrary.CurrentLibrary };
ExcelComAddInHelper.LoadComAddIn(_addin);

LoadComAddIn checks if the class has ProgId/Guid attribute, and if not it generates id based on the xll path. It works well if you e.g. extend ExcelRibbon class, but ExcelCustomTaskPaneAddIn is an internal class, so you cannot do much with it, therefore it always uses generated id.

govert commented 3 years ago

That sounds reasonable. Do you mean you need to register the control and CTP add-in in the registry yourself, or at another time?

The ExcelCustomTaskPane code is quite small with two classes and mostly dealing with the on-demand COM registration. So you could just make a copy of the code from https://github.com/Excel-DNA/ExcelDna/blob/master/Source/ExcelDna.Integration/ExcelCustomTaskPane.cs in your own add-in project, and rename the types to MyCustomTaskPaneFactory' andMyCustomTaskPaneAddIn. The only coupling I see with the rest of Excel-DNA is the fact that the add-in class derives fromExcelAddIn`, so you need that. I might be missing something, but it seems worth a try.

p0n3 commented 3 years ago

Do you mean you need to register the control and CTP add-in in the registry yourself, or at another time?

I just need to have a fixed ProgId to be able to whitelist it in a whole organization. So from my perspective it might be even hardcoded in the library ([ProgId("ExcelDna.CTP")] or smth like that)

you could just make a copy of the code

I tried, but the problem is there are bunch of internal classes/interfaces inside this file that cannot be accessed from another assembly like: ICustomTaskPaneConsumer, ProgIdRegistration, ClsIdRegistration, SingletonClassFactoryRegistration which uses another internal method - RegisterClassFactory and so on and so on.

govert commented 3 years ago

OK - I see there is some more plumbing behind it, including the class factory provided by Excel-DNA.

theboyknowsclass commented 2 years ago

any word on this?