How to add a ribbon button in Adapter for Microsoft Word?
Ribbon Extensibility
This sample demonstrates the capability of adding a new ribbon button, along with handling conditional validation and execution of associated action. The sample also additionally demonstrates the capability of moving the out-of-the-box ribbon buttons of ‘Done Editing’ and ‘Discard changes’ to the ribbon in Home Tab.
In general, using ribbon extensibility following use cases can be achieved
- Add new ribbon elements with custom validations and actions.
- Override existing ribbon control actions and validations.
- Override existing ribbon control icons or strings.
Add-In Extensibility
This sample also demonstrates the capability of tweaking the save routine using the BeforeSave event.
To demonstrate the same, it sets the asset name in the following format:
Enhanced add-in extensibility opens immense possibilities for developers by allowing access to the Application object, also see https://msdn.microsoft.com/en-us/library/office/ff194565.aspx
Developers can register for various native Microsoft Word events and also programmatically override the Ribbon class.
Configuration
To configure the sample, follow the steps mentioned below:
Update publish version
If published version of the Add-in is already installed then create copy of
Note: If you have changed the published version then in the configuration steps below, wherever specified,
Override the out-of-the-box configuration
- Copy the following file to the
/Application Files/Quark.CMSAdapters.Office.Word_ folder - Quark.CMSAdapters.Samples.Office.Word.Extension.dll
- Modify the Quark.CMSAdapters.config.deploy file as follows
- Add the highlighted content below to the
section: <appSettings> <add key="IAddInHostExtension" value="Quark.CMSAdapters.Samples.Office.Word.Extension" /> </appSettings>
- Add the highlighted content below to the
- Modify the Ribbon.config.deploy file as follows
- Add the highlighted content above <backstage onShow=”OnBackstageShow”> section:
<ribbon> <tabs> <tab idMso="TabHome"> <group id="CMSTabGroupShow" getLabel="GetLabel"> <button id="CMSCheckIn4" tag="Id=CMSCheckIn;SaveSilently=false;SaveAsMinorVersion=;KeepMoreOptionsExpanded=" getImage="GetImage" getLabel="GetLabel" getEnabled="IsActionEnabled" onAction="Save" size="large"/> <button id="CMSCancelCheckout2" tag="Id=CMSCancelCheckout" getImage="GetImage" getLabel="GetLabel" getEnabled="IsActionEnabled" onAction="CancelCheckout" size="large"/> <button id="SampleActionId" getImage="GetControlImage" getLabel="GetControlLabel" getEnabled="IsSampleActionEnabled" onAction="SampleAction" size="large" /> </group> </tab> </tabs> </ribbon>
- Add the highlighted content above <backstage onShow=”OnBackstageShow”> section:
Update the ClickOnce VSTO installer
- Delete <Publish Location>/Application Files/Quark.CMSAdapters.Office.Word_<Publish Version>/ Quark.CMSAdapters.Office.Word.vsto file.
- Open Visual studio command prompt and run command “Mage” which will open Mage tool
- Go to File->Open and select <Publish Location>/Application Files/Quark.CMSAdapters.Office.Word_<Publish Version>/Quark.CMSAdapters.Office.Word.dll.manifest file.
- Go to “Name” and set version number as specified in the name of Quark.CMSAdapters.Office.Word.dll.manifest file’s folder.
- Go to “Files” and select check box “When populating add the .deploy extension to any file that does not have it” and click on Populate button as shown below
- Go to File -> Save and select “Yes” in the Validation dialog as shown below.
- Select option “Sign with certificate file” and provide the certificate file and password and click “OK”.
- Close Mage tool.
- Open Visual studio command prompt and run following command
mage -Update “<Publish Location>/Quark.CMSAdapters.Office.Word.vsto” -AppManifest “<Publish Location>/Application Files/Quark.CMSAdapters.Office.Word_<Publish Version>\Quark.CMSAdapters.Office.Word.dll.manifest” -CertFile “<Certificate Location>\<Certificate>.pfx” -Password “<Password>”
- Copy the <Publish Location>/Quark.CMSAdapters.Office.Word.vsto to <Publish Location>/Application Files/Quark.CMSAdapters.Office.Word_<Publish Version> folder