Hello Govert. Is there a tutorial for using Excel-DNA with F#?

467 views
Skip to first unread message

Fernando Saldanha

unread,
Aug 29, 2017, 2:58:35 AM8/29/17
to Excel-DNA
I built a financial application with F# and would like to embed it in an Excel spreadsheet. Is this possible? If yes, how do I learn how to do it?

Govert van Drimmelen

unread,
Aug 29, 2017, 6:11:13 AM8/29/17
to exce...@googlegroups.com
There are a few samples using F# with Excel-DNA, and I'm happy to help with any questions.
You can start by making an F# Class Library project, then installing the ExcelDna.AddIn package from NuGet and copying in the code from the Readme into your source file.
Then it should compile and run and give you a new UDF in Excel.

Once you have that working, you can look at some of the F# samples you'll find online:
* A nice introduction written by Natallie Baikevich: http://luajalla.azurewebsites.net/excel-dna-three-stories/
* Quite a big financial library with F# and Excel-DNA from Bram Jochems: https://github.com/bramjochems/MyExcelLib
* And an F# object handler implementation from David Carlson: https://github.com/mndrake/ExcelObjectHandler

The Excel-DNA Registration extensions also have some support for the F# async functions and observable events - https://github.com/Excel-DNA/Registration

The embedding question is a bit harder. Excel-DNA add-ins are native Excel .xll add-ins, so UDFs and macros are global to Excel and not tied to a particular workbook. So although you can embed your add-in into a workbook, the functions won't actually have any relationship with the workbook.
Easiest is just to distribute the .xll file itself. You might add some macros and a ribbon extension to your add-in that creates (or extract from an embedded resource) a template workbook which uses your functions - kind of turning around the relationship between the code and the workbook.

-Govert
--
You received this message because you are subscribed to the Google Groups "Excel-DNA" group.
To unsubscribe from this group and stop receiving emails from it, send an email to exceldna+u...@googlegroups.com.
To post to this group, send email to exce...@googlegroups.com.
Visit this group at https://groups.google.com/group/exceldna.
For more options, visit https://groups.google.com/d/optout.

Fernando Saldanha

unread,
Aug 31, 2017, 3:35:02 PM8/31/17
to Excel-DNA
Thanks for the answer. I have progressed quite a bit. I can use a macro to fill a horizontal range with the commands let cellC1E1 = app.Range("C1:E1") and cellC1E1.Value(XlRangeValueDataType.xlRangeValueDefault) <- [|6; 7; 8|]. However, I was not able to fill a vertical range with more than one value. For example, let cellF13 = app.Range("F1:F3") followed by cellF13.Value(XlRangeValueDataType.xlRangeValueDefault) <- [|6; 7; 8|] fills the range F1:F3 with three sixes. 

Fernando Saldanha

unread,
Aug 31, 2017, 4:41:29 PM8/31/17
to Excel-DNA
I also noticed that my application runs much slower when it is functioning as an add-in. Would that be because it is a Console Application in which I simply inserted some ExcelDNA code? Would it run faster if I had built it as a Library?


On Tuesday, August 29, 2017 at 7:11:13 AM UTC-3, Govert van Drimmelen wrote:

Govert van Drimmelen

unread,
Aug 31, 2017, 4:42:07 PM8/31/17
to exce...@googlegroups.com
I think you'll need to use a 2D array (with one column) to fill a vertical range.

cellF13.Value(XlRangeValueDataType.xlRangeValueDefault) <- array2D [ [6]; [7]; [8] ]


-Govert


From: exce...@googlegroups.com [exce...@googlegroups.com] on behalf of Fernando Saldanha [fsal...@gmail.com]
Sent: 31 August 2017 09:35 PM
To: Excel-DNA
Subject: Re: [ExcelDna] Hello Govert. Is there a tutorial for using Excel-DNA with F#?

Reply all
Reply to author
Forward
0 new messages