Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where does Factory come from?

I am trying to add items to splitbuttons and galleries. The issue is with the Factory. In the following OfficeRibbon code file Factory is unknown. It is also unknown in the addin code file. I am missing a reference somewhere. I have also tried Globals.Factory still unknown.

RibbonButton rc = this.Factory.CreateRibbonButton(); 

I have the following using statements.

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Text.RegularExpressions;
using System.Threading;
using System.Windows.Forms;
using Microsoft.Office.Interop.Excel;
using Microsoft.Office.Tools.Ribbon;
//using Microsoft.Office.Tools.Excel.Extensions;

This code also fails in the ThisAddin.cs which has been renamed to ReqCommon.cs in my project.

My desired end goal is to dynamically add items to these two controls. Examples i have found here and elsewhere all seem predicated on this elusive Factory.

The project does reference Microsoft.Office.Tools.Common.v9.0.dll

like image 248
Joe Johnston Avatar asked Aug 16 '12 23:08

Joe Johnston


1 Answers

If you are using the Ribbon Designer - it will automatically create this Factory for you (Globals.Factory.GetRibbonFactory()) - otherwise you need to create your own Factory by overriding CreateRibbonExtensibilityObject() in ThisAddin.cs (your ReqCommon.cs)

protected override Microsoft.Office.Core.IRibbonExtensibility CreateRibbonExtensibilityObject()
{  
    Ribbon1 tempRibbon = new Ribbon1();
    tempRibbon.tab1.ControlId.ControlIdType = Microsoft.Office.Tools.Ribbon.RibbonControlIdType.Office;
    tempRibbon.tab1.ControlId.OfficeId = "TabHome";
    return Globals.Factory.GetRibbonFactory().CreateRibbonManager(new Microsoft.Office.Tools.Ribbon.IRibbonExtension[] { tempRibbon });   
}

The Ribbon Designer inherits from Ribbon.RibbonBase which contains the property RibbonBase.Factory which enables this.Factory to be used within it.

like image 50
SliverNinja - MSFT Avatar answered Oct 25 '22 07:10

SliverNinja - MSFT