I developed Excel addin to Visual Studio 2012.Use projects Excel 2010 Add-in. In the project has created a Ribbon (XML):
[ComVisible(true)]
public class PricelistRibbon : Office.IRibbonExtensibility
{
private Office.IRibbonUI _ribbon;
public PricelistRibbon()
{
}
public event EventHandler ClickButtonRibben;
protected virtual void OnClickButtonRibben()
{
var handler = ClickButtonRibben;
if (handler != null) handler(this, EventArgs.Empty);
}
#region IRibbonExtensibility Members
public string GetCustomUI(string ribbonID)
{
return GetResourceText("ProcessingPricelist.PricelistRibbon.xml");
}
#endregion
#region Ribbon Callbacks
//Create callback methods here. For more information about adding callback methods, select the Ribbon XML item in Solution Explorer and then press F1
public void Ribbon_Load(Office.IRibbonUI ribbonUI)
{
_ribbon = ribbonUI;
}
public void OnAction(Office.IRibbonControl control)
{
OnClickButtonRibben();
}
#endregion
#region Helpers
private static string GetResourceText(string resourceName)
{
Assembly asm = Assembly.GetExecutingAssembly();
string[] resourceNames = asm.GetManifestResourceNames();
for (int i = 0; i < resourceNames.Length; ++i)
{
if (string.Compare(resourceName, resourceNames[i], StringComparison.OrdinalIgnoreCase) == 0)
{
using (StreamReader resourceReader = new StreamReader(asm.GetManifestResourceStream(resourceNames[i])))
{
if (resourceReader != null)
{
return resourceReader.ReadToEnd();
}
}
}
}
return null;
}
#endregion
}
In ThisAddIn working with ribbon like this:
public partial class ThisAddIn
{
private void ThisAddIn_Startup(object sender, EventArgs e)
{
}
private void ThisAddIn_Shutdown(object sender, EventArgs e)
{
}
protected override Microsoft.Office.Core.IRibbonExtensibility CreateRibbonExtensibilityObject()
{
var pricelistRibbon = new PricelistRibbon();
pricelistRibbon.ClickButtonRibben += PricelistRibbonOnClickButtonRibben;
return pricelistRibbon;
}
private void PricelistRibbonOnClickButtonRibben(object sender, EventArgs eventArgs)
{
var control = sender as Office.IRibbonControl;
if (control == null) return;
try
{
Application.ScreenUpdating = false;
switch (control.Id)
{
case "customButton1":
CreateSpecification();
break;
//..............
}
}
catch (Exception throwedException)
{
MessageBox.Show(throwedException.Message, @"Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
finally
{
Application.ScreenUpdating = true;
}
}
private void CreateSpecification()
{
}
#region VSTO generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InternalStartup()
{
Startup += ThisAddIn_Startup;
Shutdown += ThisAddIn_Shutdown;
}
#endregion
}
Next I deploys this addin via ClickOnce. Installed MS Office 2007. Addin deployed successfully. In the settings you can see that Excel addin installed but not visible on the tape my TabControl. If I create a Ribbon (Visual Designer) instead of the Ribbon (xml) when the tape appears TabControl. How can I fix it?