Git Product home page Git Product logo

exceldna.com.quickstart.v2's Introduction

ExcelDna.COM.QuickStart.V2

EXCEL DNA COM Sample : Generation of an XLL file to be used in VBA.
This is a v2 version, more detailed, of project ExcelDna.COM.QuickStart.

alt capture1

INTRO

You should know that Excel DNA allows to expose UDF functions under Excel Sheets.

  • as formula in cell
  • directly via VBA Code with :
Application.Run("[my function name here]")

To do so, these functions are implemented in C# as public static in static class.

Yet besides to this, and more powerful: we will demonstrate any C# functions could be COM exposed. The Goal of the produced XLL is to expose, via COM technology, C# functions which can be used under VBA Excel code.

STEPS TO FOLLOW

1. Generation of the XLL

  • Check Post Build event of project "DataApi.XLAddin", this will:
  • Generate tlb files
  • Build a DataApi.XLAddin-packed.xll.
  • Copy DataApi.XLAddin-packed.xll to lib\DataApi.XLAddin.xll (renaming)
  • Copy DataApi.XLAddin.xll.config to lib\DataApi.XLAddin.xll.config

alt capture2

tlb files will allow any C# functions to be COM exposed.

2. Referencing the DataApi.XLAddin.xll.

  • Open Excel
  • Load the DataApi.XLAddin.xll.
    Or, Open Excel, Tools > References > Browse in order to add the generated lib\DataApi.XLAddin.xll

alt capture3

alt capture4

alt capture5

In a classical COM registration process, user will need to add tlb as VBA References, then regsvr32 these tlb.
The drawback of this method is that it will register in the personal local registry.

With EXCEL DNA, we do not need to reference the tlb anymore but the .xll:
DataApi.XLAddin.xll contains all the plumbing in the .dna file.
At each use, the xll will register in a personal "on-the-fly" EXCEL DNA virtual env.

What dll is COMVisible:

<ExternalLibrary Path="DataApiXLAddin.dll" ComServer="true" Pack="true" />

Auto-registration routine is implemented in class:

ExcelAddin.cs

3. Testing with the sample XL for demo

  • Open Sample "Sheet_Testing_XLL.xlsm" and browse for the xll as shown in step 2.
  • Input order parameters and click to book the order.

4. Logging has been implemented with log4net, to allow it:

  • log4net.dll is packed in .dna config
<Reference Path="log4net.dll" LoadFromBytes="true" Pack="true" />
  • loaded via DataApi.XLAddin > AssemblyInfo.cs file:
[assembly: log4net.Config.XmlConfigurator]
  • Files "DataApi.XLAddin.xll.config" and referenced "DataApi.XLAddin.xll" must be in the same directory
  • File "DataApi.XLAddin.xll.config" is configured by default to log in directory :
C:\log 

5. Additionnal: Check sample codes for details https://github.com/Excel-DNA/ExcelDna

ExcelDna-master\ExcelDna-master\Distribution\Samples\ComServer 

ADDITIONNAL NOTES

1. Define what's COM visible or not :

In "AutoDual" mode, we do not need to declare an interface ICOMFooBar to define what will be explicitely COM Visible.
However, default methods such as :
Equals(), GetHashCode(), GetType(), ToString() will appeared as COM Visible and available for use in EXCEL VBA.

A sample class has been written "COMFooBar.cs" for demo purpose:

alt capture6

alt capture7

2. HOW TO : Pass a string array from VBA to COM C# : use of LoadComObjectIntoTArray

In order to set the string[] AdditionnalInfos property of Trade class, please check the demonstration in COMTrade class :

public void SetAdditionnalInfos(object addInfosStringArray)    

Call in VBA

Dim additionnalInfosArr(3) As String
...
comTrade.SetAdditionnalInfos (additionnalInfosArr)

Help and details here.

exceldna.com.quickstart.v2's People

Contributors

danmgs avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.