Featured post
vsto - Open XML SDK - Adding a macro programatically to a Word 2007 document -
i trying dynamically add new custom ribbon in word 2007 document following teh manual method described in article :- http://msdn.microsoft.com/en-us/library/aa338202(v=office.12).aspx.
the article specifies following :-
a) create xml file named customui.xml contain elements want display in tab , put same in folder named customui.
b) rename word 2007 document .zip. add above "customui" folder zip file.
c) add following relationship "_rels/rels" file in .zip file :-
<relationship type="http://schemas.microsoft.com/office/2006/ relationships/ui/extensibility" target="/customui/customui.xml" id="customuirelid" />
do have code sample achieve same using openxml sdk? example, how add "ribbonextensibilitypart" (which contains ribbon xml) document?
edit :-
this how did above mentioned steps:-
string documentfilename = <path of docx file>; string ribbonxml = <path of ribbon xml file>; using (wordprocessingdocument mydoc = wordprocessingdocument.open(documentfilename, true)) { maindocumentpart mainpart = mydoc.maindocumentpart; if (mydoc.getpartscountoftype<ribbonextensibilitypart>() > 0) mydoc.deletepart(mydoc.getpartsoftype<ribbonextensibilitypart>().first()); ribbonextensibilitypart ribbonextensibilitypart = mydoc.addnewpart<ribbonextensibilitypart>(); ribbonextensibilitypart.customui = new documentformat.openxml.office.customui.customui(file.readalltext(ribbonxml)); mydoc.createrelationshiptopart(ribbonextensibilitypart); }
and able see new ribbon elements in it. however, have buttons in ribbon , want add handle actions on buttons. following ribbon xml looks :-
<customui xmlns="http://schemas.microsoft.com/office/2006/01/customui"> <ribbon> <tabs> <tab id="customtab" label="my tab"> <group id="mygroup" label="my group" > <button id="button1" label="my large button" size="large"/> <button id="button2" label="my normal button" size="normal" *onaction="thisdocument.myotherbuttonmacro"* /> </group > </tab> </tabs> </ribbon> </customui>
have @ "onaction="thisdocument.myotherbuttonmacro". know can write macro function in document. however, custom ribbon added dynamically on server-side, not sure how can add macro dynamically. help?
- Get link
- X
- Other Apps
Comments
Post a Comment