c# - Openxml Add another different footer to an existing docx -
i trying add different footer after each altchunk added. code changes footers , on last page there 2 footers. adding section break prior adding new footer different text. (c# , openxml)
public static void appendfooter(string sfttext, string sfile) { using (wordprocessingdocument wddoc = wordprocessingdocument.open(sfile, true)) { maindocumentpart mypart = wddoc.maindocumentpart; footerpart newftpart = mypart.addnewpart<footerpart>(); string ft_id = mypart.getidofpart(newftpart); makefooterpart(sfttext).save(newftpart); foreach (sectionproperties sectproperties in mypart.document.descendants<sectionproperties>()) { footerreference newftreference = new footerreference() { id = ft_id, type = headerfootervalues.default }; sectproperties.append(newftreference); } // save changes main document part. mypart.document.save(); } }
////////////////////////////////////////////
private static footer makefooterpart(string footertext) { var element = new footer( new paragraph( new paragraphproperties( new paragraphstyleid() { val = "footer" }), new run( new text(footertext)) ) ); return element; }
Comments
Post a Comment