# Project.Excel.DNA.1801.Demo **Repository Path**: serfend/Project.Excel.DNA.1801.Demo ## Basic Information - **Project Name**: Project.Excel.DNA.1801.Demo - **Description**: No description available - **Primary Language**: C# - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 1 - **Created**: 2020-02-05 - **Last Updated**: 2022-06-04 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Ribbon Sample This sample shows how to add a ribbon UI extension with the Excel-DNA add-in, and how to use the Excel COM object model from C# to write some information to a workbook. ## Initial setup The initial setup will create a new add-in with a simple test function (it's a useful indicator to show that the add-in is loaded into the Excel session). 1. Create new Class Library project. 2. Install `ExcelDna.AddIn` package. 3. Add a small test function: ```cs namespace Ribbon { public static class Functions { public static string dnaRibbonTest() { return "Hello from the Ribbon Sample!"; } } } ``` 4. Press F5 to load in Excel, and then test `=dnaRibbonTest()` in a cell. ## Add the ribbon controller Next we add a class to implement the ribbon UI extension, with a simple button. 1. Add a reference to the `System.Windows.Forms` assembly (we'll use that for showing our messages). 2. Add a new class for the ribbon controller (maybe `RibbonController.cs`), with this code for a button and handler: ```cs using System.Runtime.InteropServices; using System.Windows.Forms; using ExcelDna.Integration.CustomUI; namespace Ribbon { [ComVisible(true)] public class RibbonController : ExcelRibbon { public override string GetCustomUI(string RibbonID) { return @"