コード例 #1
0
        /// <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++;
            }
        }
コード例 #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);
            }
        }
コード例 #3
0
        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);
            }
        }
コード例 #4
0
        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);
            }
        }
コード例 #5
0
ファイル: Utilities.cs プロジェクト: leonchen09/poc
        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);
        }