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


C# XWPFParagraph.GetRuns方法代码示例

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


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

示例1: TestExisting

        public void TestExisting()
        {
            XWPFDocument doc = XWPFTestDataSamples.OpenSampleDocument("TestDocument.docx");
            XWPFParagraph p;
            XWPFRun run;

            // First paragraph is simple
            p = doc.GetParagraphArray(0);
            Assert.AreEqual("This is a test document.", p.GetText());
            Assert.AreEqual(2, p.GetRuns().Count);

            run = p.GetRuns()[0];
            Assert.AreEqual("This is a test document", run.ToString());
            Assert.AreEqual(false, run.IsBold());
            Assert.AreEqual(false, run.IsItalic());
            Assert.AreEqual(false, run.IsStrike());
            Assert.AreEqual(null, run.GetCTR().rPr);

            run = p.GetRuns()[1];
            Assert.AreEqual(".", run.ToString());
            Assert.AreEqual(false, run.IsBold());
            Assert.AreEqual(false, run.IsItalic());
            Assert.AreEqual(false, run.IsStrike());
            Assert.AreEqual(null, run.GetCTR().rPr);

            // Next paragraph is all in one style, but a different one
            p = doc.GetParagraphArray(1);
            Assert.AreEqual("This bit is in bold and italic", p.GetText());
            Assert.AreEqual(1, p.GetRuns().Count);

            run = p.GetRuns()[0];
            Assert.AreEqual("This bit is in bold and italic", run.ToString());
            Assert.AreEqual(true, run.IsBold());
            Assert.AreEqual(true, run.IsItalic());
            Assert.AreEqual(false, run.IsStrike());
            Assert.AreEqual(true, run.GetCTR().rPr.IsSetB());
            Assert.AreEqual(false, run.GetCTR().rPr.b.IsSetVal());

            // Back to normal
            p = doc.GetParagraphArray(2);
            Assert.AreEqual("Back to normal", p.GetText());
            Assert.AreEqual(1, p.GetRuns().Count);

            run = p.GetRuns()[(0)];
            Assert.AreEqual("Back to normal", run.ToString());
            Assert.AreEqual(false, run.IsBold());
            Assert.AreEqual(false, run.IsItalic());
            Assert.AreEqual(false, run.IsStrike());
            Assert.AreEqual(null, run.GetCTR().rPr);

            // Different styles in one paragraph
            p = doc.GetParagraphArray(3);
            Assert.AreEqual("This contains BOLD, ITALIC and BOTH, as well as RED and YELLOW text.", p.GetText());
            Assert.AreEqual(11, p.GetRuns().Count);

            run = p.GetRuns()[(0)];
            Assert.AreEqual("This contains ", run.ToString());
            Assert.AreEqual(false, run.IsBold());
            Assert.AreEqual(false, run.IsItalic());
            Assert.AreEqual(false, run.IsStrike());
            Assert.AreEqual(null, run.GetCTR().rPr);

            run = p.GetRuns()[(1)];
            Assert.AreEqual("BOLD", run.ToString());
            Assert.AreEqual(true, run.IsBold());
            Assert.AreEqual(false, run.IsItalic());
            Assert.AreEqual(false, run.IsStrike());

            run = p.GetRuns()[2];
            Assert.AreEqual(", ", run.ToString());
            Assert.AreEqual(false, run.IsBold());
            Assert.AreEqual(false, run.IsItalic());
            Assert.AreEqual(false, run.IsStrike());
            Assert.AreEqual(null, run.GetCTR().rPr);

            run = p.GetRuns()[(3)];
            Assert.AreEqual("ITALIC", run.ToString());
            Assert.AreEqual(false, run.IsBold());
            Assert.AreEqual(true, run.IsItalic());
            Assert.AreEqual(false, run.IsStrike());

            run = p.GetRuns()[(4)];
            Assert.AreEqual(" and ", run.ToString());
            Assert.AreEqual(false, run.IsBold());
            Assert.AreEqual(false, run.IsItalic());
            Assert.AreEqual(false, run.IsStrike());
            Assert.AreEqual(null, run.GetCTR().rPr);

            run = p.GetRuns()[(5)];
            Assert.AreEqual("BOTH", run.ToString());
            Assert.AreEqual(true, run.IsBold());
            Assert.AreEqual(true, run.IsItalic());
            Assert.AreEqual(false, run.IsStrike());

            run = p.GetRuns()[(6)];
            Assert.AreEqual(", as well as ", run.ToString());
            Assert.AreEqual(false, run.IsBold());
            Assert.AreEqual(false, run.IsItalic());
            Assert.AreEqual(false, run.IsStrike());
            Assert.AreEqual(null, run.GetCTR().rPr);
//.........这里部分代码省略.........
开发者ID:hanwangkun,项目名称:npoi,代码行数:101,代码来源:TestXWPFRun.cs


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