Exemple #1
0
        public bool SaveExportInfo(Workbook workbook)
        {
            //clear old export item information xml
            foreach (CustomXMLPart curXmlPart in workbook.CustomXMLParts)
            {
                if (curXmlPart.BuiltIn)
                {
                    continue;
                }
                XmlObject customObject = ObjectSerializeHelper.Deserialize <XmlObject>(curXmlPart.XML);
                if (customObject.ContentType == ContentType.PdeExportItem)
                {
                    curXmlPart.Delete();
                    break;
                }
            }
            //add new information
            CustomXMLPart xmlPart      = workbook.CustomXMLParts.Add();
            string        xmlContent   = ObjectSerializeHelper.SerializeToString <PdeExports>(new PdeExports(exportItems));
            XmlObject     excelContent = new XmlObject(xmlContent, ContentType.PdeExportItem);

            xmlPart.LoadXML(ObjectSerializeHelper.SerializeToString <XmlObject>(excelContent));

            return(true);
        }
Exemple #2
0
        void Application_WindowBeforeDoubleClick(Selection sel, ref bool Cancel)
        {
            int n = sel.ContentControls.Count;

            Microsoft.Office.Interop.Word.ContentControl cp = sel.Range.ParentContentControl;

            String mytitle = null;
            String sid     = null;

            if (cp != null)
            {
                mytitle = cp.Title;
                sid     = cp.ID;


                if (mytitle == "violet")
                {
                    Debug.WriteLine("control selected " + sid);
                    string xid = cp.Tag;

                    Microsoft.Office.Tools.Word.Document vstoDocument = Globals.Factory.GetVstoObject(this.Application.ActiveDocument);
                    CustomXMLPart xmlpart = vstoDocument.CustomXMLParts.SelectByID(xid);
                    string        xml     = xmlpart.XML;


                    Globals.Ribbons.Ribbon1.initPath(xml);

                    Globals.Ribbons.Ribbon1.RibbonUI.ActivateTabMso("TabAddIns");
                }
            }



            //throw new NotImplementedException();
        }
Exemple #3
0
        public static void RestoreControls(this Document doc)
        {
            CustomXMLPart xmlPart = GetCustomXmlPart(doc, FormControlXmlPartIdPropertyName, false, false);

            if (xmlPart == null)
            {
                //TODO: EXCEPTION TYPE
                throw new ArgumentNullException();
            }

            var bookmarks = doc.Bookmarks.Cast <Word.Bookmark>().Select(b =>
                                                                        new
            {
                Name = b.Name, Range = b.Range
            });

            XmlNode root = GetSpecificCustomXmlRootNode(xmlPart);

            if ((bookmarks.Count() == 0 && root.ChildNodes.Count != 0) ||
                (bookmarks.Count() != 0 && root.ChildNodes.Count == 0))
            {
                //TODO: EXCEPTION TYPE
                throw new ArgumentException();
            }

            Assembly executingAssembly = Assembly.GetExecutingAssembly();

            foreach (XmlNode node in root.ChildNodes)
            {
                RecreateFormControl(doc, node.Name, node.OuterXml, executingAssembly, bookmarks);
            }
        }
        /// <summary>Removes all custom parts that have Poll namespace</summary>
        /// <returns>True if succeeded otherwise false</returns>
        public bool RemoveAll()
        {
            try
            {
                for (int i = _ppt.CustomXMLParts.Count; i >= 1; i--)
                {
                    CustomXMLPart part  = _ppt.CustomXMLParts[i];
                    bool          found = false;
                    foreach (CustomXMLPrefixMapping ns in part.NamespaceManager.Cast <CustomXMLPrefixMapping>())
                    {
                        if (ns.NamespaceURI.Equals(DEFAULT_NS))
                        {
                            found = true;
                            break;
                        }
                    }

                    if (found)
                    {
                        _ppt.CustomXMLParts[i].Delete();
                    }
                }

                return(true);
            }
            catch (Exception)
            {
                throw;
            }
        }
Exemple #5
0
        public static CustomXMLPart FindCustomXmlPart(string id, Word.Document document)
        {
            CustomXMLPart result = null;

            Word.Document activeDocument     = document;
            string        activeDocumentName = activeDocument.Name;

            foreach (Word.Document otherDocument in activeDocument.Application.Documents)
            {
                if (!otherDocument.Name.Equals(activeDocumentName))
                {
                    foreach (
                        CustomXMLPart customXmlPart in AllChemistryParts(otherDocument))
                    {
                        string molId = GetCmlId(customXmlPart);
                        if (molId.Equals(id))
                        {
                            result = customXmlPart;
                            break;
                        }
                    }
                }
                if (result != null)
                {
                    break;
                }
            }

            return(result);
        }
Exemple #6
0
        public static CustomXMLPart FindCustomXmlPart(string id, Word.Document document)
        {
            CustomXMLPart result = null;

            Word.Document activeDocument     = document;
            string        activeDocumentName = activeDocument.Name;

            foreach (Word.Document otherDocument in activeDocument.Application.Documents)
            {
                if (!otherDocument.Name.Equals(activeDocumentName))
                {
                    //Debug.WriteLine("Looking in " + otherDoc.Name);
                    foreach (
                        CustomXMLPart x in
                        otherDocument.CustomXMLParts.SelectByNamespace("http://www.xml-cml.org/schema"))
                    {
                        string molId = GetCmlId(x);
                        if (molId.Equals(id))
                        {
                            result = x;
                            break;
                        }
                    }
                }
                if (result != null)
                {
                    break;
                }
            }

            return(result);
        }
        internal void BindContentControls(DataAccess.Netflix.Title title)
        {
            var           doc            = Globals.Factory.GetVstoObject(this.Application.ActiveDocument);
            const string  xmlPartName    = "http://netflix/titles";
            var           customXmlParts = doc.CustomXMLParts.SelectByNamespace(xmlPartName);
            CustomXMLPart customXmlPart  = null;

            if (customXmlParts != null && customXmlParts.Count > 0)
            {
                customXmlPart = customXmlParts[1];
            }

            foreach (Word.ContentControl cc in doc.ContentControls)
            {
                if (!cc.XMLMapping.IsMapped)
                {
                    //if (cc.Type == WdContentControlType.wdContentControlPicture)
                    //{
                    //    ManuallySetImage(doc, cc, title);
                    //}
                    //else
                    {
                        cc.LockContents = false;
                        var xpath = string.Format("//titles/title[@id='{0}']/{1}", title.Id, cc.Tag.ToLower());
                        cc.XMLMapping.SetMapping(xpath, "", customXmlPart);
                    }
                }
            }
        }
        // GET: /<controller>/
        public IActionResult XMLMapping(string Group)
        {
            if (Group == null)
            {
                return(View());
            }
            string basePath = _hostingEnvironment.WebRootPath;
            // Load Template document stream.
            FileStream inputStream = new FileStream(basePath + @"/DocIO/Employees.xml", FileMode.Open, FileAccess.Read);

            // Create a new document.
            WordDocument document = new WordDocument();

            //Add a section & a paragraph in the empty document.
            document.EnsureMinimal();

            //Loads XML file into the customXML part of the Word document.
            CustomXMLPart docIOxmlPart = new CustomXMLPart(document);

            docIOxmlPart.Load(inputStream);

            //Insert content controls and maps Employees details to it.
            InsertAndMapEmployees(document, "EmployeesList", docIOxmlPart);

            FormatType type        = FormatType.Docx;
            string     filename    = "Sample.docx";
            string     contenttype = "application/vnd.ms-word.document.12";

            MemoryStream ms = new MemoryStream();

            document.Save(ms, type);
            document.Close();
            ms.Position = 0;
            return(File(ms, contenttype, filename));
        }
        void OnButtonClicked(object sender, EventArgs e)
        {
            Assembly assembly    = Assembly.GetExecutingAssembly();
            Stream   inputStream = assembly.GetManifestResourceStream("SampleBrowser.Samples.DocIO.Templates.Employees.xml");

            // Create a new document.
            WordDocument document = new WordDocument();

            //Add a section & a paragraph in the empty document.
            document.EnsureMinimal();

            //Loads XML file into the customXML part of the Word document.
            CustomXMLPart docIOxmlPart = new CustomXMLPart(document);

            docIOxmlPart.Load(inputStream);

            //Insert content controls and maps Employees details to it.
            InsertAndMapEmployees(document, "EmployeesList", docIOxmlPart);
            MemoryStream stream = new MemoryStream();

            document.Save(stream, FormatType.Word2013);
            document.Close();

            if (stream != null)
            {
                SaveiOS iOSSave = new SaveiOS();
                iOSSave.Save("XMLMapping.docx", "application/msword", stream);
            }
        }
Exemple #10
0
        public static CustomXMLPart GetCustomXmlPart(string id, Word.Document activeDocument)
        {
            CustomXMLPart result = null;

            string guid = GuidFromTag(id);

            if (!string.IsNullOrEmpty(guid))
            {
                Word.Document doc = activeDocument;

                foreach (CustomXMLPart xmlPart in doc.CustomXMLParts.SelectByNamespace("http://www.xml-cml.org/schema"))
                {
                    string cmlId = GetCmlId(xmlPart);
                    if (!string.IsNullOrEmpty(cmlId))
                    {
                        if (cmlId.Equals(guid))
                        {
                            result = xmlPart;
                            break;
                        }
                    }
                }
            }

            return(result);
        }
Exemple #11
0
        private static CustomXMLPart GetCustomXmlPart(Document doc, string xmlPartIdName, bool createNew = true, bool clearContent = true)
        {
            string        xmlPartId = GetCustomProperty(doc, xmlPartIdName);
            CustomXMLPart xmlPart   = null;

            if (string.IsNullOrEmpty(xmlPartId))
            {
                if (createNew)
                {
                    xmlPart = doc.CustomXMLParts.Add();
                }
            }
            else
            {
                xmlPart = doc.CustomXMLParts.SelectByID(xmlPartId);

                if (xmlPart == null)
                {
                    if (createNew)
                    {
                        xmlPart = doc.CustomXMLParts.Add();
                    }
                }
                else if (clearContent)
                {
                    xmlPart.Delete();
                    xmlPart = doc.CustomXMLParts.Add();
                }
            }

            return(xmlPart);
        }
Exemple #12
0
        public static CustomXMLPart GetCustomXmlPart(string id, Word.Document activeDocument)
        {
            CustomXMLPart result = null;

            string guid = GuidFromTag(id);

            if (!string.IsNullOrEmpty(guid))
            {
                Word.Document doc = activeDocument;

                foreach (CustomXMLPart xmlPart in AllChemistryParts(doc))
                {
                    string cmlId = GetCmlId(xmlPart);
                    if (!string.IsNullOrEmpty(cmlId))
                    {
                        if (cmlId.Equals(guid))
                        {
                            result = xmlPart;
                            break;
                        }
                    }
                }
            }

            return(result);
        }
Exemple #13
0
        ///<summary>
        ///</summary>
        ///<param name="document"></param>
        ///<returns></returns>
        public static ControlProperties[] Load(_Document document)
        {
            Log.Debug(string.Format(CultureInfo.InvariantCulture, "ControlsStorage - Load : document {0}", document));

            ControlProperties[] controls = null;
            CustomXMLParts      parts    = document.CustomXMLParts.SelectByNamespace(ControlsStorageNamespace);

            if (parts != null && parts.Count > 0)
            {
                Debug.Assert(parts.Count == 1);
                CustomXMLPart part = parts[1];
                XmlDocument   doc  = new XmlDocument();
                doc.LoadXml(part.XML);

                XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable);
                nsmgr.AddNamespace("sc", ControlsStorageNamespace);

                XmlElement controlsElement =
                    doc.SelectSingleNode(String.Format(CultureInfo.CurrentUICulture, "//sc:{0}", ControlsNodeName),
                                         nsmgr) as XmlElement;
                if (controlsElement != null)
                {
                    byte[]          data      = Convert.FromBase64String(controlsElement.InnerXml);
                    BinaryFormatter formatter = new BinaryFormatter();
                    controls = (ControlProperties[])formatter.Deserialize(new MemoryStream(data));
                }
            }

            return(controls);
        }
        public ActionResult XMLMapping(string Button)
        {
            if (Button == null)
            {
                return(View());
            }

            #region XML Mapping

            // Create a new document.
            WordDocument document = new WordDocument();

            //Add a section & a paragraph in the empty document.
            document.EnsureMinimal();

            //Loads XML file into the customXML part of the Word document.
            CustomXMLPart docIOxmlPart = new CustomXMLPart(document);
            docIOxmlPart.Load(ResolveApplicationDataPath("Employees.xml", "Data\\DocIO"));

            //Insert content controls and maps Employees details to it.
            InsertAndMapEmployees(document, "EmployeesList", docIOxmlPart);
            #endregion

            return(document.ExportAsActionResult("Sample.docx", FormatType.Docx, HttpContext.ApplicationInstance.Response, HttpContentDisposition.Attachment));
        }
Exemple #15
0
        /// <summary>
        /// Button click event for XMLMapping.
        /// </summary>
        /// <param name="sender">Sender</param>
        /// <param name="e">Event args</param>
        private void OnButtonClicked(object sender, EventArgs e)
        {
            // Load Template document stream.
            Stream inputStream = typeof(XMLMapping).GetTypeInfo().Assembly.GetManifestResourceStream("SampleBrowser.DocIO.Samples.Templates.Employees.xml");

            // Create a new document.
            WordDocument document = new WordDocument();

            //Add a section & a paragraph in the empty document.
            document.EnsureMinimal();

            //Loads XML file into the customXML part of the Word document.
            CustomXMLPart docIOxmlPart = new CustomXMLPart(document);

            docIOxmlPart.Load(inputStream);

            //Insert content controls and maps Employees details to it.
            InsertAndMapEmployees(document, "EmployeesList", docIOxmlPart);

            MemoryStream stream = new MemoryStream();

            document.Save(stream, FormatType.Docx);
            document.Close();

            if (Device.OS == TargetPlatform.WinPhone || Device.OS == TargetPlatform.Windows)
            {
                DependencyService.Get <ISaveWindowsPhone>()
                .Save("XMLMapping.docx", "application/msword", stream);
            }
            else
            {
                DependencyService.Get <ISave>().Save("XMLMapping.docx", "application/msword", stream);
            }
        }
Exemple #16
0
        private void button1_Click(object sender, System.EventArgs e)
        {
            try
            {
                // Get XML file path.
                string dataPath = Application.StartupPath + @"..\..\..\..\..\..\..\common\Data\DocIO\";
                // Create a new document.
                WordDocument document = new WordDocument();

                //Add a section & a paragraph in the empty document.
                document.EnsureMinimal();

                //Loads XML file into the customXML part of the Word document.
                CustomXMLPart docIOxmlPart = new CustomXMLPart(document);
                docIOxmlPart.Load(System.IO.Path.Combine(dataPath, "Employees.xml"));

                //Insert content controls and maps Employees details to it.
                InsertAndMapEmployees(document, "EmployeesList", docIOxmlPart);

                //Saving the document as .docx
                document.Save("Sample.docx", FormatType.Docx);
                document.Close();

                //Message box confirmation to view the created document.
                if (MessageBoxAdv.Show("Do you want to view the generated Word document?", "Document has been created", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
                {
                    try
                    {
                        //Launching the MS Word file using the default Application.[MS Word Or Free WordViewer]
#if NETCORE
                        System.Diagnostics.Process process = new System.Diagnostics.Process();
                        process.StartInfo = new System.Diagnostics.ProcessStartInfo("Sample.docx")
                        {
                            UseShellExecute = true
                        };
                        process.Start();
#else
                        System.Diagnostics.Process.Start("Sample.docx");
#endif
                        //Exit
                        this.Close();
                    }
                    catch (Win32Exception ex)
                    {
                        MessageBoxAdv.Show("Microsoft Word Viewer or Microsoft Word is not installed in this system");
                        Console.WriteLine(ex.ToString());
                    }
                }
                else
                {
                    // Exit
                    this.Close();
                }
            }
            catch (Exception Ex)
            {
                MessageBox.Show(Ex.Message);
            }
        }
Exemple #17
0
        /// <summary>
        /// Occurs after a new custom XMl part is loaded into the document
        /// Useful for updating the Navigator
        /// </summary>
        /// <param name="NewPart"></param>
        private void OnPartAfterLoad(CustomXMLPart NewPart)
        {
            string module = $"{_product}.{_class}.{MethodBase.GetCurrentMethod().Name}()";

            try
            {
                var converter = new CMLConverter();
                //get the chemistry
                var chemModel = converter.Import(NewPart.XML);
                //find out which content control macthes the custom XML part
                try
                {
                    // ReSharper disable once InconsistentNaming
                    var matchingCC = (from ContentControl cc in _doc.ContentControls
                                      orderby cc.Range.Start
                                      where CustomXmlPartHelper.GuidFromTag(cc?.Tag) == CustomXmlPartHelper.GetCmlId(NewPart)
                                      select cc).First();

                    //get the ordinal position of the content control
                    int start = 0;
                    foreach (ContentControl cc in _doc.ContentControls)
                    {
                        if (cc.ID == matchingCC.ID)
                        {
                            break;
                        }
                        start += 1;
                    }

                    //insert the new navigator item at the ordinal position
                    var newNavItem = new NavigatorItem()
                    {
                        CMLId             = matchingCC?.Tag,
                        ChemicalStructure = NewPart.XML,
                        XMLPart           = NewPart,
                        Name = chemModel.ConciseFormula
                    };
                    try
                    {
                        NavigatorItems.Insert(start, newNavItem);
                    }
                    catch (ArgumentOutOfRangeException) //can happen when there are more content controls than navigator items
                    {
                        //so simply insert the new navigator item at the end
                        NavigatorItems.Add(newNavItem);
                    }
                }
                catch (InvalidOperationException)
                {
                    //sequence contains no elements - thrown on close
                    //just ignore
                }
            }
            catch (Exception ex)
            {
                new ReportError(Globals.Chem4WordV3.Telemetry, Globals.Chem4WordV3.WordTopLeft, module, ex).ShowDialog();
            }
        }
Exemple #18
0
        /// <summary>
        /// Function which Marks a individual word as Abbreviation or Acronym
        /// </summary>
        public void Individual() {
            CustomXMLParts xmlparts = currentDoc.CustomXMLParts;

            //If call is from Abbreviation button
            if (checkAbbrAcr) {
                object val = System.Reflection.Missing.Value;
                String nameAbbr = "Abbreviations" + GenerateId().ToString();
                currentDoc.Application.Selection.Bookmarks.Add(nameAbbr, ref val);

                for (int i = 1; i <= xmlparts.Count; i++) {
                    if (xmlparts[i].NamespaceURI == "http://Daisy-OpenXML/customxml") {
                        String partxml = xmlparts[i].XML;
                        customXml.LoadXml(partxml);

                        XmlElement elmtItem = customXml.CreateElement("Item", "http://Daisy-OpenXML/customxml");
                        elmtItem.SetAttribute("AbbreviationName", nameAbbr);
                        elmtItem.SetAttribute("FullAbbr", tBx_MarkFullForm.Text.TrimEnd());
                        elmtItem.SetAttribute("OriginalText", currentDoc.Application.Selection.Text.Trim());

                        customXml.FirstChild.FirstChild.AppendChild(elmtItem);

                        //Deleting the Current CustomXML
                        xmlparts[i].Delete();

                        //Adding the updated CustomXml to the Current Document
                        CustomXMLPart part = currentDoc.CustomXMLParts.Add(customXml.InnerXml, System.Reflection.Missing.Value);
                        this.Close();
                    }
                }
            } else {
                object val = System.Reflection.Missing.Value;
                String nameAcr = "Acronyms" + pronounceAbbrAcr + GenerateId().ToString();
                currentDoc.Application.Selection.Bookmarks.Add(nameAcr, ref val);

                for (int i = 1; i <= xmlparts.Count; i++) {

                    if (xmlparts[i].NamespaceURI == "http://Daisy-OpenXML/customxml") {
                        String partxml = xmlparts[i].XML;
                        customXml.LoadXml(partxml);

                        XmlElement elmtItem = customXml.CreateElement("Item", "http://Daisy-OpenXML/customxml");
                        elmtItem.SetAttribute("AcronymName", nameAcr);
                        elmtItem.SetAttribute("FullAcr", tBx_MarkFullForm.Text.TrimEnd());
                        elmtItem.SetAttribute("OriginalText", currentDoc.Application.Selection.Text.Trim());

                        customXml.FirstChild.FirstChild.NextSibling.AppendChild(elmtItem);

                        //Deleting the Current CustomXML
                        xmlparts[i].Delete();

                        //Adding the updated CustomXml to the Current Document
                        CustomXMLPart part = currentDoc.CustomXMLParts.Add(customXml.InnerXml, System.Reflection.Missing.Value);
                        this.Close();
                    }
                }
            }
        }
Exemple #19
0
        public static void SaveExcelToDoc(docx.Document doc, string ExcelFile)
        {
            CustomXMLPart xmlPart = doc.CustomXMLParts.Add();
            //XmlObject excelContent = new XmlObject(ExcelToBase64(ExcelFile));
            string xmlContent = ExcelToBase64(ExcelFile);

            xmlContent = "<?xml version=\"1.0\" encoding=\"UTF-16\"?><content>" + xmlContent + "</content>";
            xmlPart.LoadXML(xmlContent);
        }
Exemple #20
0
        public RemapForm(Microsoft.Office.Interop.Word.ContentControl _cc)
        {
            selectedCC = _cc;
            InitializeComponent();
            this.TopMost = true;

            XMLHandler.Populate_customXMLComboBoxWithCustomXMLParts(customXMLPartsComboBox, true);

            customXMLPart = ((ComboBoxItem)customXMLPartsComboBox.Items[0]).Tag as CustomXMLPart;
        }
Exemple #21
0
        /// <summary>
        /// Gets an XML part from the Word document.
        /// </summary>
        /// <param name="partNamespace">The namespace of the part being looked for.</param>
        /// <returns>The XML part with the corresponding namespace, <c>null</c> if the part is not found.</returns>
        public CustomXMLPart GetXmlPart(string partNamespace)
        {
            CustomXMLPart ans = null;

            if (this.document.CustomXMLParts.SelectByNamespace(partNamespace).Count > 0)
            {
                ans = this.document.CustomXMLParts[partNamespace];
            }

            return(ans);
        }
Exemple #22
0
        public void Delete()
        {
            if (!FindAndSetIdByKey())
            {
                throw new KeyNotFoundException();
            }

            CustomXMLPart xmlPart = _document.CustomXMLParts.SelectByID(_id);

            xmlPart.Delete();
        }
Exemple #23
0
        /// <summary>
        /// Gets the data for a custom XML part.
        /// </summary>
        /// <param name="partNamespace">The namespace of the part to retrieve.</param>
        /// <returns>The XML data in the custom XML part, or <c>null</c> if the part does not exist.</returns>
        private string GetXmlPartData(string partNamespace)
        {
            string        ans  = null;
            CustomXMLPart part = this.wordDocument.GetXmlPart(partNamespace);

            if (part != null)
            {
                ans = part.XML;
            }

            return(ans);
        }
Exemple #24
0
        public string Read()
        {
            if (!FindAndSetIdByKey())
            {
                throw new KeyNotFoundException();
            }

            CustomXMLPart xmlPart = _document.CustomXMLParts.SelectByID(_id);

            XElement root = XDocument.Parse(xmlPart.XML).Root;

            return(root?.Value == null ? null : FromBase64(root.Value));
        }
Exemple #25
0
        private void CustomXMLComboBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (customXMLPartsComboBox.SelectedItem != null)
            {
                //Clear the TreeView
                customXMLPartTreeView.Nodes.Clear();

                //Load the custom Xml Part and transform it into XDocument
                customXMLPart = ((ComboBoxItem)customXMLPartsComboBox.SelectedItem).Tag as CustomXMLPart;
                CustomXMLNode node = customXMLPart.SelectSingleNode("/*");
                Populate_customXMLPartTreeView(node);
            }
        }
Exemple #26
0
        public bool SaveMapInfo(Workbook workbook)
        {
            //clear old map information xml
            foreach (CustomXMLPart curXmlPart in workbook.CustomXMLParts)
            {
                if (curXmlPart.BuiltIn)
                {
                    continue;
                }
                XmlObject customObject = ObjectSerializeHelper.Deserialize <XmlObject>(curXmlPart.XML);
                if (customObject.ContentType == ContentType.PdeMapInfo)
                {
                    curXmlPart.Delete();
                    break;
                }
            }
            //add new map information
            CustomXMLPart xmlPart      = workbook.CustomXMLParts.Add();
            string        xmlContent   = ObjectSerializeHelper.SerializeToString <MapInfo>(mapInfo);
            XmlObject     excelContent = new XmlObject(xmlContent, ContentType.PdeMapInfo);

            xmlPart.LoadXML(ObjectSerializeHelper.SerializeToString <XmlObject>(excelContent));

            //Generate new xsd file and import it.
            GenXsd genXsd = new GenXsd();

            prepareData(genXsd);
            XmlMap xmap = genXsd.ImportXsd(workbook);

            //add xpath for each mapped cell and table
            foreach (MapNode mn in mapInfo.Maps)
            {
                if (mn.type == MapType.SingleCell)
                {
                    Range c = workbook.Application.get_Range(mn.target);
                    c.XPath.SetValue(xmap, mn.xPath);
                }
                else
                {
                    string[]   target    = mn.target.Split('!');
                    Worksheet  worksheet = workbook.Sheets[target[0]];
                    ListObject lst       = worksheet.ListObjects[target[1]];
                    foreach (TabCol tc in mn.columns)
                    {
                        lst.ListColumns[tc.columnName].XPath.SetValue(xmap, tc.xPath);
                    }
                }
            }

            return(true);
        }
        public void InitializeCustomXML_treeView()
        {
            customXML_treeView.Nodes.Clear();
            customXML_treeView.Nodes.Add(new TreeNode("Root"));
            TreeNode root = customXML_treeView.Nodes[0];

            Debug.WriteLine(root.Text);
            if (customXMLPartsComboBox.SelectedItem != null)
            {
                CustomXMLPart customPart = ((System.Windows.Controls.ComboBoxItem)customXMLPartsComboBox.SelectedItem).Tag as CustomXMLPart;
                CustomXMLNode customNode = customPart.SelectSingleNode("/*");
                XMLHandler.BuildNodes(root, customNode);
            }
        }
Exemple #28
0
        /// <summary>
        /// handles deletion of an XML Part...removes the corresponding navigator item
        /// </summary>
        /// <param name="OldPart">The custom XML part that gets deleted</param>
        private void OnPartBeforeDelete(CustomXMLPart OldPart)
        {
            string module = $"{_product}.{_class}.{MethodBase.GetCurrentMethod().Name}()";

            try
            {
                var oldPart = NavigatorItems.FirstOrDefault(ni => CustomXmlPartHelper.GetCmlId(ni.XMLPart) == CustomXmlPartHelper.GetCmlId(OldPart));
                NavigatorItems.Remove(oldPart);
            }
            catch (Exception ex)
            {
                new ReportError(Globals.Chem4WordV3.Telemetry, Globals.Chem4WordV3.WordTopLeft, module, ex).ShowDialog();
            }
        }
        public void LoadXML_VadliXmlValue_LoadsIt()
        {
            // Arrange
            using (var workbook = this.ExcelApplication.Workbooks.Add())
            {
                CustomXMLPart cxp1 = workbook.CustomXMLParts.Add();

                // Act
                cxp1.LoadXML("<discounts><discount>0.10</discount></discounts>");

                // Assert
                Assert.AreEqual("<discounts><discount>0.10</discount></discounts>", cxp1.XML);
            }
        }
        public void AddNode_NullObjects_ShouldWork()
        {
            // Arrange
            using (var workbook = this.ExcelApplication.Workbooks.Add())
            {
                CustomXMLPart cxp1 = workbook.CustomXMLParts.Add("<invoice />");
                CustomXMLNode cxn  = cxp1.SelectSingleNode("/invoice");

                // Act
                Assert.Throws <MethodCOMException>(() => cxp1.AddNode(cxn, null, null, null, null, null));

                // Assert
                // Assert.AreEqual(@"<invoice><upccode xmlns=""urn: invoice:namespace""/></invoice>", cxp1.XML);
            }
        }
 public ContentControls SelectUnlinkedControls(CustomXMLPart Stream = null)
 {
     throw new System.NotImplementedException();
 }