/// <summary> /// Change the currently active document. /// </summary> internal void ChangeCurrentDocument() { Debug.WriteLine("Changing event document to " + Globals.ThisAddIn.Application.ActiveDocument.Name); //unhook existing events m_wddoc.ContentControlOnEnter -= (Word.DocumentEvents2_ContentControlOnEnterEventHandler)m_alDocumentEvents[0]; m_wddoc.ContentControlAfterAdd -= (Word.DocumentEvents2_ContentControlAfterAddEventHandler)m_alDocumentEvents[1]; m_parts.PartAfterAdd -= (Office._CustomXMLPartsEvents_PartAfterAddEventHandler)m_alPartsEvents[0]; m_parts.PartBeforeDelete -= (Office._CustomXMLPartsEvents_PartBeforeDeleteEventHandler)m_alPartsEvents[1]; m_parts.PartAfterLoad -= (Office._CustomXMLPartsEvents_PartAfterLoadEventHandler)m_alPartsEvents[2]; m_currentPart.NodeAfterDelete -= (Office._CustomXMLPartEvents_NodeAfterDeleteEventHandler)m_alPartEvents[0]; m_currentPart.NodeAfterInsert -= (Office._CustomXMLPartEvents_NodeAfterInsertEventHandler)m_alPartEvents[1]; m_currentPart.NodeAfterReplace -= (Office._CustomXMLPartEvents_NodeAfterReplaceEventHandler)m_alPartEvents[2]; //release the streams + stream handler references m_alDocumentEvents.Clear(); m_alPartsEvents.Clear(); m_alPartEvents.Clear(); //clean up the m_wddoc object (since otherwise the RCW gets disposed out from under it) m_wddoc = null; GC.WaitForPendingFinalizers(); GC.Collect(); GC.WaitForPendingFinalizers(); GC.Collect(); //hook up new objects m_wddoc = Globals.ThisAddIn.Application.ActiveDocument; m_parts = m_wddoc.CustomXMLParts; m_currentPart = m_parts[1]; SetupEventHandlers(); }
public DocumentEvents(Controls.ControlMain cm) { //get the initial part m_cmTaskPane = cm; m_wddoc = Globals.ThisAddIn.Application.ActiveDocument; m_parts = m_wddoc.CustomXMLParts; m_currentPart = cm.model.getUserPart(System.Configuration.ConfigurationManager.AppSettings["RootElement"]); //hook up event handlers SetupEventHandlers(); }
public DocumentEvents(Controls.ControlMain cm) { //get the initial part m_cmTaskPane = cm; m_wddoc = Globals.ThisAddIn.Application.ActiveDocument; m_parts = m_wddoc.CustomXMLParts; m_currentPart = m_parts[1]; //hook up event handlers SetupEventHandlers(); }
public static void UpdateCustomXmlNode(Excel.Workbook workbook, string namespaceName, string xmlString, string xPath) { Office.CustomXMLParts ps = workbook.CustomXMLParts.SelectByNamespace(namespaceName); foreach (Office.CustomXMLPart p in ps) { var nsmgr = p.NamespaceManager; nsmgr.AddNamespace("x", namespaceName); Office.CustomXMLNode oldNode = p.SelectSingleNode(xPath); oldNode.ParentNode.ReplaceChildSubtree(xmlString, oldNode); } }
private string GetNovenaReportingWorkbookPropertiesXML(Excel.Workbook Wb) { Office.CustomXMLParts allXMLParts = Wb.CustomXMLParts; foreach (Office.CustomXMLPart part in allXMLParts) { if (part.DocumentElement.BaseName == "WorkbookProperties") { return(part.XML); } } return(null); }
public static List <string> ListXmlNamespaces(Excel.Workbook workbook) { var result = new List <string>(); Office.CustomXMLParts ps = workbook.CustomXMLParts; for (int i = 1; i <= workbook.CustomXMLParts.Count; i++) { Office.CustomXMLPart p = ps[i]; //p.BuiltIn will be true for internal buildin excel parts if (p != null && !p.BuiltIn) { result.Add(p.NamespaceURI); } } return(result); }
public static Office.CustomXMLNode GetCustomXmlNode(Excel.Workbook workbook, string xNameSpace, string xPath) { Office.CustomXMLParts ps = workbook.CustomXMLParts; ps = ps.SelectByNamespace(xNameSpace); for (int i = 1; i <= ps.Count; i++) { Office.CustomXMLPart p = ps[i]; var nsmgr = p.NamespaceManager; nsmgr.AddNamespace("x", xNameSpace); Office.CustomXMLNode node = p.SelectSingleNode(xPath); if (node != null) { return(node); } } return(null); }
internal void ConnectCurrent() { //hook up new objects m_wddoc = Globals.ThisAddIn.Application.ActiveDocument; m_parts = m_wddoc.CustomXMLParts; //m_currentPart = m_parts[1]; // bad that this is done here as well! m_cmTaskPane.model = OpenDoPEModel.Model.ModelFactory(m_wddoc); m_cmTaskPane.formPartList.Dispose(); m_cmTaskPane.formPartList = new Forms.FormSwitchSelectedPart(); m_cmTaskPane.formPartList.controlPartList.controlMain = m_cmTaskPane; if (m_cmTaskPane.model.userParts.Count == 0) { log.Error("No users part found! This shouldn't happen!"); } m_currentPart = m_cmTaskPane.model.userParts[0]; SetupEventHandlers(); }
public static T GetCustomXmlByNamespace <T>(Excel.Workbook workbook, string namespaceStr) where T : class, new() { if (null == workbook) { throw new ArgumentNullException("workbook"); } if (string.IsNullOrWhiteSpace(namespaceStr)) { throw new ArgumentNullException("namespaceStr"); } Office.CustomXMLParts parts = workbook.CustomXMLParts.SelectByNamespace(namespaceStr); if (0 == parts.Count) { return(new T()); } Office.CustomXMLNode node = parts[1].DocumentElement.FirstChild; string json = node.NodeValue.Trim(); return(JsonConvert.DeserializeObject <T>(json)); }
public static int CountXmlNamespace(Excel.Workbook workbook, string xNameSpace) { Office.CustomXMLParts ps = workbook.CustomXMLParts; ps = ps.SelectByNamespace(xNameSpace); return(ps.Count); }