Ribbon not showing up with dynamically generated ribbon XML from the database

一曲冷凌霜 提交于 2019-12-13 03:57:34

问题


I am trying to form ribbon XML with the data from the database and following is what I wrote:-

  XNamespace xNameSpace = "http://schemas.microsoft.com/office/2006/01/customui";
  XDocument document = new XDocument();
  document.Add( new XElement (xNameSpace+"customUI"
                , new XElement("ribbon"
                , new XElement("tabs"))));
  // more code to add the groups and the controls with-in the groups
  .......
  // code below to add ribbon XML to the document and to add the relationship
   RibbonExtensibilityPart ribbonExtensibilityPart = myDoc.AddNewPart<RibbonExtensibilityPart>();
   ribbonExtensibilityPart.CustomUI = new DocumentFormat.OpenXml.Office.CustomUI.CustomUI(ribbonXml.ToString());

   myDoc.CreateRelationshipToPart(ribbonExtensibilityPart); 

I don't see any error executing the above. However, when I open the changed document, I dont see my ribbon added. I see following in the CustomUI/CustomUI.xml inside the word:-

<?xml version="1.0" encoding="utf-8"?><customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui">
  <ribbon xmlns="">
    <tabs>
.....

I am not sure how the "xmlns" attribute is getting added to the ribbon element. When I remove that attribute, the ribbon gets showed.

Could anybody throw any idea on where am I going wrong?


回答1:


I ended up string replacing that string xmlns="" with empty string from the ribbon tag.



来源:https://stackoverflow.com/questions/4533863/ribbon-not-showing-up-with-dynamically-generated-ribbon-xml-from-the-database

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!