当前位置: 首页>>代码示例>>C#>>正文


C# Run.GetFirstChild方法代码示例

本文整理汇总了C#中Run.GetFirstChild方法的典型用法代码示例。如果您正苦于以下问题:C# Run.GetFirstChild方法的具体用法?C# Run.GetFirstChild怎么用?C# Run.GetFirstChild使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Run的用法示例。


在下文中一共展示了Run.GetFirstChild方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: FillText

 protected void FillText(ref Run runElement, string strFormat)
 {
     if (runElement.HasChildren)
     {
         runElement.GetFirstChild<Text>().Text = strFormat;
         //runElement.RemoveAllChildren<Text>();
         //runElement.AppendChild<Text>(new Text(GeneralFormatter.ToString(rows[i], property.FormatString)));
     }
     else
     {
         runElement.AppendChild<Text>(new Text(strFormat));
     }
 }
开发者ID:jerryshi2007,项目名称:AK47Source,代码行数:13,代码来源:GeneralDataProcessor.cs

示例2: LeafElementValidateTest

        public void LeafElementValidateTest()
        {
            string runOuterXml = "<w:r xmlns:w=\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\">" +
            "<w:rPr><w:strike /><w:vanish><!-- comments is ok --></w:vanish><w:webHidden><w:invalidChild /></w:webHidden></w:rPr>" +
            "<w:t>Run Text.</w:t><w:t><!-- comments is ok -->Text 2</w:t><w:t>Text 3.<invalidElement /></w:t></w:r>";

            SchemaValidator target = new SchemaValidator();
            var openxmlElement = new Run(runOuterXml);
            ValidationResult result = target.Validate(openxmlElement);
            Assert.False(result.Valid);
            Assert.Equal(2, result.Errors.Count);

            Assert.Same(openxmlElement.GetFirstChild<RunProperties>().WebHidden, result.Errors[0].Node);
            Assert.Equal("Sch_InvalidChildinLeafElement", result.Errors[0].Id);
            Assert.Equal("The element 'http://schemas.openxmlformats.org/wordprocessingml/2006/main:webHidden' is a leaf element and cannot contain children.", result.Errors[0].Description);

            Assert.Same(openxmlElement.LastChild, result.Errors[1].Node);
            Assert.Equal("Sch_InvalidChildinLeafElement", result.Errors[1].Id);
            Assert.Equal("The element 'http://schemas.openxmlformats.org/wordprocessingml/2006/main:t' is a leaf element and cannot contain children.", result.Errors[1].Description);
        }
开发者ID:eriawan,项目名称:Open-XML-SDK,代码行数:20,代码来源:SchemaValidatorTest.cs

示例3: TestRemoveRunTextBeforeIndex_SetsPreserveSpaceIfTextStartsWithWhitespace

 public void TestRemoveRunTextBeforeIndex_SetsPreserveSpaceIfTextStartsWithWhitespace()
 {
     Run target = new Run();
     target.AppendChild<Text>(new Text("This is a test string."));
     OxmlDocument.RemoveRunTextBeforeIndex(target, 4);
     EnumValue<SpaceProcessingModeValues> expected =
         SpaceProcessingModeValues.Preserve;
     var actual = target.GetFirstChild<Text>().Space;
     Assert.AreEqual(expected.Value, actual.Value);
 }
开发者ID:cthiange,项目名称:eagle,代码行数:10,代码来源:OxmlDocumentTest.cs

示例4: TestRemoveRunTextBeforeIndex_DoesNotSetSpaceIfTextStartsWithNonWhitespace

 public void TestRemoveRunTextBeforeIndex_DoesNotSetSpaceIfTextStartsWithNonWhitespace()
 {
     Run target = new Run();
     target.AppendChild<Text>(new Text("This is a test string."));
     OxmlDocument.RemoveRunTextBeforeIndex(target, 2);
     var actual = target.GetFirstChild<Text>().Space;
     Assert.AreEqual(null, actual);
 }
开发者ID:cthiange,项目名称:eagle,代码行数:8,代码来源:OxmlDocumentTest.cs

示例5: LeafAndLeafTextElementLoadTest

        public void LeafAndLeafTextElementLoadTest()
        {
            string runOuterXml = "<w:r xmlns:w=\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\">" +
            "<w:rPr><w:strike /><w:vanish><!-- comments is ok --></w:vanish><w:webHidden><w:invalidChild /></w:webHidden></w:rPr>" +
            "<w:t>Run Text.</w:t><w:t><!-- comments is ok -->Text 2</w:t><w:t>Text 3.<invalidElement /></w:t></w:r>";
        
            var openxmlElement = new Run(runOuterXml);

            var strike = openxmlElement.RunProperties.Strike;
            Assert.Null(strike.ShadowElement);

            var varnish = openxmlElement.RunProperties.Vanish;
            Assert.Equal(XmlNodeType.Comment, (varnish.ShadowElement.FirstChild as OpenXmlMiscNode).XmlNodeType);
            Assert.Equal("<!-- comments is ok -->", varnish.InnerXml);
            Assert.Equal("<w:vanish xmlns:w=\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\"><!-- comments is ok --></w:vanish>", varnish.OuterXml);

            var webHidden = openxmlElement.RunProperties.WebHidden;
            Assert.Equal("invalidChild", (webHidden.ShadowElement.FirstChild as OpenXmlUnknownElement).LocalName);
            Assert.Equal("<w:invalidChild xmlns:w=\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\" />", webHidden.InnerXml);
            Assert.Equal("<w:webHidden xmlns:w=\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\"><w:invalidChild xmlns:w=\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\" /></w:webHidden>", webHidden.OuterXml);

            var t1 = openxmlElement.GetFirstChild<Text>();
            Assert.Null(t1.ShadowElement);
            Assert.Equal("Run Text.", t1.Text);
            Assert.Equal("Run Text.", t1.InnerXml);
            Assert.Equal("<w:t xmlns:w=\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\">Run Text.</w:t>", t1.OuterXml);

            var t2 = t1.NextSibling() as Text;
            Assert.Equal(XmlNodeType.Comment, (t2.ShadowElement.FirstChild as OpenXmlMiscNode).XmlNodeType);
            Assert.Equal("Text 2", t2.Text);
            Assert.Equal("<!-- comments is ok -->Text 2", t2.InnerXml);
            Assert.Equal("<w:t xmlns:w=\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\"><!-- comments is ok -->Text 2</w:t>", t2.OuterXml);

            var t3 = t2.NextSibling() as Text;
            Assert.Equal(XmlNodeType.Text, (t3.ShadowElement.FirstChild as OpenXmlMiscNode).XmlNodeType);
            Assert.Equal("invalidElement", (t3.ShadowElement.LastChild as OpenXmlUnknownElement).LocalName);
            Assert.Equal("Text 3.", t3.Text);
            Assert.Equal("Text 3.<invalidElement />", t3.InnerXml);
            Assert.Equal("<w:t xmlns:w=\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\">Text 3.<invalidElement /></w:t>", t3.OuterXml);

            // bug #725597
            var run = new Run("<w:r xmlns:w=\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\"><w:t xml:space=\"preserve\"><w:rFonts w:hint=\"eastAsia\" /></w:t></w:r>");
            var text = run.FirstChild as Text;
            Assert.Equal("<w:rFonts w:hint=\"eastAsia\" xmlns:w=\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\" />", text.InnerXml);
            Assert.Equal("<w:t xml:space=\"preserve\" xmlns:w=\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\"><w:rFonts w:hint=\"eastAsia\" /></w:t>", text.OuterXml);
        }
开发者ID:eriawan,项目名称:Open-XML-SDK,代码行数:46,代码来源:OpenXmlElementTest.cs


注:本文中的Run.GetFirstChild方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。