best way to interface D code to Excel

Arjan via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Jun 18 04:36:48 PDT 2015


On Wednesday, 17 June 2015 at 18:35:36 UTC, Laeeth Isharc wrote:
> Hi.
>
> Any thoughts on the best way to write D functions that I can 
> call from Excel?  I am completely unfamiliar with Windows 
> programming and COM (last time I wrote this kind of thing was 
> in the mid-90s I think using xloper and C).
>
> The easiest way for now seems to be via pyxll and pyd.  Wrap 
> the D function using pyd and then call it from an annotated 
> pyxll python function.  That's probably good enough for a 
> start, but it requires python to be installed on each user 
> machine which I would rather not have as the end game - just a 
> single xll would be perfect.
>
> I know D has support for COM - not sure of its status.  And 
> there was a Microsoft chap who posted here a couple of years 
> back - wonderful templated code that made it easy to write this 
> kind of thing.  Unfortunately he wasn't able to share it 
> publicly.
>
> So I would like to write:
> 1. worksheet function that will function picker and have help 
> text in the picker.  In general will take some combination of 
> strings, doubles and arrays of doubles as arguments and return 
> either string, double, or range/matrix of doubles.
> 2. vba function with similar kinds of arguments and return 
> values.
>
> I know it's easy to do this with double** and the like - at 
> least on the VBA side.  I got a bit stuck navigating the 
> headers when it comes to Excel strings.
>
> If anyone has some source they could point me to, and some 
> reading material then I would very much appreciate it.  This 
> might help facilitate adoption of D within a large financial 
> institution, but it is early days yet.  And I would guess this 
> is a common sort of use for people operating in a financial 
> environment, since people are still attached to spreadsheets.
>
> Thanks.
>
>
> Laeeth.

You actually want to create ActiveX/COM components in D?
See the 'COM in plain C' articles by Jeff Glatt which demonstrate 
how to do it using C. This might give you the information needed 
to do it using D.
http://www.codeproject.com/Articles/Jeff-Glatt#articles.

An idea to accelerate a little might be to use Visual Studio with 
C++ to create ActiveX/COM interfaces, wrappers, etc of the 
components and do the actual implementation of the interfaces in 
D.

Books (old): "Inside COM" and "Essential COM" might be handy to 
get hold of.

HTH.
Arjan


More information about the Digitalmars-d-learn mailing list