/// <summary>
        /// Inserts content control and maps the employees details to it.
        /// </summary>
        /// <param name="document">Word document instance.</param>
        /// <param name="xmlRootPath">Custom XML root Xpath.</param>
        /// <param name="docIOxmlPart">CustomXMLPart instance.</param>
        private void InsertAndMapEmployees(WordDocument document, string xmlRootPath, CustomXMLPart docIOxmlPart)
        {
            //Retrieving CustomXMLNode from xmlRootPath.
            CustomXMLNode parentNode = docIOxmlPart.SelectSingleNode(xmlRootPath);

            int empIndex = 1;

            foreach (CustomXMLNode employeeNode in parentNode.ChildNodes)
            {
                if (employeeNode.HasChildNodes())
                {
                    //Adds new paragraph to the section
                    IWParagraph paragraph = document.LastSection.AddParagraph();
                    paragraph.ParagraphFormat.BackColor = Color.Gray;

                    IWTextRange textrange = paragraph.AppendText("Employee");
                    textrange.CharacterFormat.TextColor = Color.White;
                    textrange.CharacterFormat.Bold      = true;
                    textrange.CharacterFormat.FontSize  = 14;

                    //Insert content controls and maps Employee details to it.
                    InsertAndMapEmployee(document, employeeNode, xmlRootPath, docIOxmlPart, empIndex);
                }
                empIndex++;
            }
        }
Exemple #2
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);
            }
        }
        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);
            }
        }
        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);
            }
        }
Exemple #5
0
        private static XmlNode GetSpecificCustomXmlRootNode(CustomXMLPart xmlPart)
        {
            if (xmlPart == null)
            {
                throw new ArgumentNullException();
            }

            CustomXMLNode xmlNode = xmlPart.SelectSingleNode(XmlPartContentNodePath);

            XmlDocument xmlDoc = new XmlDocument();

            xmlDoc.LoadXml(xmlNode.Text);

            XmlNode root = xmlDoc.SelectNodes("/*")[0];

            return(root);
        }