Simple C# Excel Add-In Ribbon Button to Color Cells

CodingIsAwesome picture CodingIsAwesome · Aug 19, 2011 · Viewed 8.2k times · Source

First, a big thank you to anyone that read this question and can help.

I'm sing VS2010 and I've created a Excel 2007 Add-In Project using the wizard, then I added a new folder to my project called Ribbon, and inside it created a New Item which is a Ribbon (Visual Designer).

From here I've added a new group to the ribbon and a new button. I double clicked on the new button and am presented with this code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Office.Tools.Ribbon;
using System.Xml.Linq;

namespace UploadFCStats.Ribbon
{
    public partial class FCRibbon
    {
        private void FCRibbon_Load(object sender, RibbonUIEventArgs e)
        {

        }

        private void button1_Click(object sender, RibbonControlEventArgs e)
        {

        }
    }
}

Now all I want to do is color some cells, or store some values in variables, and then create a connection to a SQL server and use an insert statement to upload some data.

However I can't seem to access any of the typical Excel properties. Now I am new at C# and Excel Add-In's but have a great understanding of C++, Java, and Excel. Nothing I've googled has helped me in this instance.

My best guess is that I'm missing a library, but after some fiddling that didn't seem to solve my problem. Using this button, how do I grab values from the worksheet? How do I color cells? How do I access formula functions inside of excel?

Thank you!

Answer

VVS picture VVS · Aug 19, 2011

Read some basics about creating an Excel 2007 Add-In and start with Globals.ThisAddIn.Application