26

I want to use C# class methods in Excel. Can anybody guid me how to do it ? The C# component will be excel add-in. How to create setup for this addin, so that I just need to give setup to user which will install add-in at client's machine. User should not need to do any other steps like registering the C# dll.

Brian Webster
  • 30,033
  • 48
  • 152
  • 225
Sambhaji
  • 990
  • 5
  • 19
  • 31

4 Answers4

42

(Disclaimer: I develop the Excel-Dna library.)

You should have a look at Excel-Dna - http://excel-dna.net. The library allows managed assemblies written in C#, VB.NET or F# to expose high-performance user-defined functions (UDFs) and macros to Excel through the native .xll interface. The project is open-source and freely allows commercial use.

With Excel-Dna you can create a single .xll add-in file that the user can open as an add-in without any further installation or registration. Excel-Dna add-ins can expose RTD servers and customized Ribbons for Excel 2007 and Excel 2010 without additional registration, so you need no extra setup program.

Govert
  • 16,387
  • 4
  • 60
  • 70
  • I am a Java programer. My work requires me to create an excel plugin or add-in (pardon my ignorance) that connects to the database via a wizard and imports data based on the options chosen by the user. Can some one point me to the right place what language etc... i know VBA allows you to create macros not sure what i would need for this :) any help is appriciated! – Shah Nov 30 '11 at 03:38
  • 1
    I've been devloping a plugin using Exceldna and it's a great library! – Niels Bosma Nov 14 '14 at 07:33
  • @govert is there a way to interact with the Excel's undo stack with Excel-DNA ? I've exhausted lots of resources in trying to find a solution to the well know issue about having the undo stack clear upon cell manipulations. I also just read the posts by Jiri Pik and now just waiting for a response from him. Thanks. – Leo Gurdian Jul 20 '16 at 06:39
  • @LeoGurdian No - I don't know of any way to interact with Excel's undo stack. (But in general, the Excel-DNA Google group is a better place for asking Excel-DNA questions than adding a comment to a random StackOverflow question ;-)) – Govert Jul 20 '16 at 13:07
  • @Govert: Can ExcelDna hook into event handlers, such as PivotTableUpdate? – B. Clay Shannon-B. Crow Raven Oct 31 '16 at 23:22
  • @B.ClayShannon Yes - you have full access to the COM object model – Govert Nov 01 '16 at 11:37
13

You will need to create a new Visual Studio project of type Excel 2007 Add-In (or Excel 2003 Add-In). The option for this can be found (in Visual Studio 2008) at:

New Project dialog -> Project types -> Visual C# -> Office

This Add-In will need to be installed on the target machine(s).

The Add-In will be able to hook into the Excel object model and therefore access any loaded spreadsheets etc.

The Add-In will also be able to add buttons to the Excel toolbar/ribbon.

Richard Ev
  • 52,939
  • 59
  • 191
  • 278
6

Try looking at VSTO, there's a section explicitly for Excel

James Bloomer
  • 5,212
  • 2
  • 22
  • 23
1

You can create Excel projects within Visual Studio (previously known as Excel VSTO projects) or you can use a third party library such as ExcelDna.

Adam Ralph
  • 29,453
  • 4
  • 60
  • 67