问题
How can I add a new group to an existing (3rd party) custom ribbon tab add-in? I know that I can add to out of box ribbons by specifying the Tabs idMSo value but how do I do that for a custom ribbon tab. I have already tried the ID value of the custom ribbon, but it juts duplicates the ribbon? have also tried idMso and idQ attributes passing in the required custom tab Id but no success.
I can add it to out of box tab group by specifying the idMso value but not to custom tab
regards
回答1:
idQ
is the right way to go. This attribute allows you specify a qualified id, i.e. an id within a namespace. Some namespaces such as mso
are built in, but custom namespaces can also be specified.
The key is that you need a xmlns:foo="bar"
attribute in your customUI
element that matches the namespace declared within the customUI
of the 3rd party add-in you are trying to extend.
For example, suppose I have the XML for the following 3rd party add-in:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<mso:customUI xmlns:mso="http://schemas.microsoft.com/office/2009/07/customui"
xmlns:foo="bar">
<mso:ribbon>
<mso:tabs>
<mso:tab idQ="foo:someTab" label="an extensible custom tab">
<mso:group id="someGroup" label="a custom group">
<mso:button id="someButton" label="button" />
</mso:group>
</mso:tab>
</mso:tabs>
</mso:ribbon>
</mso:customUI>
Now, I want to extend the existing foo:someTab
with a new group in another add-in or template. I define a customUI
in the new add-in, making sure to specify the same namespace attribute in the customUI
element. I then reference the existing tab using idQ="foo:someTab"
:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<mso:customUI xmlns:mso="http://schemas.microsoft.com/office/2009/07/customui"
xmlns:foo="bar">
<mso:ribbon>
<mso:tabs>
<mso:tab idQ="foo:someTab" label="an extensible custom tab">
<mso:group id="someOtherGroup" label="a different custom group">
<mso:button id="someOtherButton" label="a different button" />
</mso:group>
</mso:tab>
</mso:tabs>
</mso:ribbon>
</mso:customUI>
This results two groups on a single custom tab. The same approach can be used to extend groups and other container controls.
I learned this through careful study of the Office 2010 Ribbon UI XSD. Unfortunately, it's poorly documented outside of the XSD itself.
回答2:
The ribbon stuff in word is a bit weird. Basically, the way I understand it is Word asks your add in one time, via GetCustomUI, for any custom UI, Ribbom declarations, backstage, etc that you want to include.
And that's the only chance you've got. You can't dynamically add buttons, once you've told word the XML for your custom UI elements. You CAN however, unhide hidden elements, so as to make it LOOK like you're dynamically adding elements to a ribbon.
The Prob with a third party ribbon is that Word has already gotten the Custom UI from the third party app, so it's likely your running up against the same issue that third party would have if they wanted to dynamically add a button to their own ribbon.
I believe Word takes extra steps to allow you to add buttons to "built in" ribbons, but that doesn't extend to Custom ribbons as far as I know.
来源:https://stackoverflow.com/questions/3052229/add-a-custom-ribbon-group-to-an-existing-custom-ribbon-group-in-word-2007