當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。