本文整理汇总了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);
//.........这里部分代码省略.........