/// <summary> /// Stuff required to create XPath element /// (except for ID, which this method generates) /// </summary> /// <param name="xpath"></param> /// <param name="storeItemID"></param> /// <param name="prefixMappings"></param> /// <param name="questionID"></param> public static xpathsXpath updateXPathsPart( Office.CustomXMLPart xpathsPart, string xpath, string xpathId, string storeItemID, string prefixMappings, string questionID) { //Office.CustomXMLPart xpathsPart = ((WedTaskPane)this.Parent.Parent.Parent).xpathsPart; xpaths xpaths = new xpaths(); xpaths.Deserialize(xpathsPart.XML, out xpaths); xpathsXpath item = new xpathsXpath(); item.id = xpathId; //System.Guid.NewGuid().ToString(); if (!string.IsNullOrWhiteSpace(questionID)) item.questionID = questionID; xpathsXpathDataBinding db = new xpathsXpathDataBinding(); db.xpath = xpath; db.storeItemID = storeItemID; if (!string.IsNullOrWhiteSpace(prefixMappings)) db.prefixMappings = prefixMappings; item.dataBinding = db; xpaths.xpath.Add(item); // Save it in docx string result = xpaths.Serialize(); log.Info(result); CustomXmlUtilities.replaceXmlDoc(xpathsPart, result); return item; }
public void save() { // Save it in docx string result = xpaths.Serialize(); log.Info(result); CustomXmlUtilities.replaceXmlDoc(model.xpathsPart, result); }
/// <summary> /// Stuff required to create XPath element /// (except for ID, which this method generates) /// </summary> /// <param name="xpath"></param> /// <param name="storeItemID"></param> /// <param name="prefixMappings"></param> /// <param name="questionID"></param> public static xpathsXpath updateXPathsPart( Office.CustomXMLPart xpathsPart, string xpath, string xpathId, string storeItemID, string prefixMappings, string questionID) { //Office.CustomXMLPart xpathsPart = ((WedTaskPane)this.Parent.Parent.Parent).xpathsPart; xpaths xpaths = new xpaths(); xpaths.Deserialize(xpathsPart.XML, out xpaths); xpathsXpath item = new xpathsXpath(); item.id = xpathId; //System.Guid.NewGuid().ToString(); if (!string.IsNullOrWhiteSpace(questionID)) { item.questionID = questionID; } xpathsXpathDataBinding db = new xpathsXpathDataBinding(); db.xpath = xpath; db.storeItemID = storeItemID; if (!string.IsNullOrWhiteSpace(prefixMappings)) { db.prefixMappings = prefixMappings; } item.dataBinding = db; xpaths.xpath.Add(item); // Save it in docx string result = xpaths.Serialize(); log.Info(result); CustomXmlUtilities.replaceXmlDoc(xpathsPart, result); return(item); }
/// <summary> /// Create OpenDoPE parts, including optionally, question part. /// </summary> /// <param name="needQuestionsPart"></param> public void process(Microsoft.Office.Interop.Word.Document document, bool needQuestionsPart) { Model model = Model.ModelFactory(document); // Button shouldn't be available if this exists, // but .. if (model.conditionsPart == null) { conditions conditions = new conditions(); string conditionsXml = conditions.Serialize(); model.conditionsPart = addCustomXmlPart(document, conditionsXml); } if (model.componentsPart == null) { components components = new components(); string componentsXml = components.Serialize(); model.componentsPart = addCustomXmlPart(document, componentsXml); } // TODO 2013 12 if there is an existing questions part or answers part // I suspect we just want to keep it, rather than overwriting its contents! // Unless it is to do with supporting multiple Q, A parts? questionnaire q = null; if (model.questionsPart == null) { if (needQuestionsPart) { q = new questionnaire(); } } else { //needQuestionsPart = false; // Button shouldn't be available if this exists, // but .. q = new questionnaire(); questionnaire.Deserialize(model.questionsPart.XML, out q); } // Add XPath xpaths xpaths = new xpaths(); // Button shouldn't be available if this exists, // but .. if (model.xpathsPart != null) { xpaths.Deserialize(model.xpathsPart.XML, out xpaths); } if (needQuestionsPart) { // Are there content controls which need questions bool missingQuestions = false; foreach (Word.ContentControl cc in Globals.ThisAddIn.Application.ActiveDocument.ContentControls) { if (cc.XMLMapping.IsMapped) { missingQuestions = true; break; } } if (missingQuestions) { log.Warn("Document contains pre-existing bound content controls; without Questions."); System.Windows.Forms.MessageBox.Show("This docx already contains bound content controls!"); } } string xpathsXml = xpaths.Serialize(); if (model.xpathsPart == null) { model.xpathsPart = addCustomXmlPart(document, xpathsXml); } else { CustomXmlUtilities.replaceXmlDoc(model.xpathsPart, xpathsXml); } if (model.questionsPart == null && needQuestionsPart) { string qxml = q.Serialize(); model.questionsPart = addCustomXmlPart(document, qxml); } }
/// <summary> /// Create OpenDoPE parts, including optionally, question part. /// </summary> public void process() { Microsoft.Office.Interop.Word.Document document = null; try { document = Globals.ThisAddIn.Application.ActiveDocument; } catch (Exception ex) { Mbox.ShowSimpleMsgBoxError("No document is open/active. Create or open a docx first."); return; } Model model = Model.ModelFactory(document); // Button shouldn't be available if this exists, // but .. if (model.conditionsPart == null) { conditions conditions = new conditions(); string conditionsXml = conditions.Serialize(); model.conditionsPart = addCustomXmlPart(document, conditionsXml); } if (model.componentsPart == null) { components components = new components(); string componentsXml = components.Serialize(); model.componentsPart = addCustomXmlPart(document, componentsXml); } // Add XPath xpaths xpaths = new xpaths(); // Button shouldn't be available if this exists, // but .. if (model.xpathsPart != null) { xpaths.Deserialize(model.xpathsPart.XML, out xpaths); } int idInt = 1; foreach (Word.ContentControl cc in Globals.ThisAddIn.Application.ActiveDocument.ContentControls) { if (cc.XMLMapping.IsMapped) { log.Debug("Adding xpath for " + cc.ID); // then we need to add an XPath string xmXpath = cc.XMLMapping.XPath; xpathsXpath item = new xpathsXpath(); // I make no effort here to check whether the xpath // already exists, since the part shouldn't already exist! item.id = "x" + idInt; xpathsXpathDataBinding db = new xpathsXpathDataBinding(); db.xpath = xmXpath; db.storeItemID = cc.XMLMapping.CustomXMLPart.Id; if (!string.IsNullOrWhiteSpace(cc.XMLMapping.PrefixMappings)) db.prefixMappings = cc.XMLMapping.PrefixMappings; item.dataBinding = db; xpaths.xpath.Add(item); // Write tag TagData td = new TagData(cc.Tag); td.set("od:xpath", item.id); cc.Tag = td.asQueryString(); log.Debug(".. added for " + cc.ID); idInt++; } } string xpathsXml = xpaths.Serialize(); if (model.xpathsPart == null) { model.xpathsPart = addCustomXmlPart(document, xpathsXml); } else { CustomXmlUtilities.replaceXmlDoc(model.xpathsPart, xpathsXml); } Microsoft.Office.Tools.Word.Document extendedDocument = Globals.ThisAddIn.Application.ActiveDocument.GetVstoObject(Globals.Factory); //Microsoft.Office.Tools.CustomTaskPane ctp // = Globals.ThisAddIn.createCTP(document, cxp, xpathsPart, conditionsPart, questionsPart, componentsPart); //extendedDocument.Tag = ctp; //// Want a 2 way association //WedTaskPane wedTaskPane = (WedTaskPane)ctp.Control; //wedTaskPane.associatedDocument = document; //extendedDocument.Shutdown += new EventHandler( // Globals.ThisAddIn.extendedDocument_Shutdown); //taskPane.setupCcEvents(document); log.Debug("Done. Task pane now also open."); }