public void TestSetParagraphStyle() { //new clean instance of paragraph XWPFDocument doc = XWPFTestDataSamples.OpenSampleDocument("heading123.docx"); XWPFParagraph p = doc.CreateParagraph(); XWPFRun run = p.CreateRun(); run.SetText("Heading 1"); CT_SdtBlock block = doc.Document.body.AddNewSdt(); Assert.IsNull(p.Style); p.Style = HEADING1; Assert.AreEqual(HEADING1, p.GetCTP().pPr.pStyle.val); doc.CreateTOC(); /* * // TODO - finish this test * if (false) { * CTStyles styles = doc.Style; * CTStyle style = styles.AddNewStyle(); * style.Type=(STStyleType.PARAGRAPH); * style.StyleId=("Heading1"); * } * * if (false) { * File file = TempFile.CreateTempFile("testHeaders", ".docx"); * OutputStream out1 = new FileOutputStream(file); * doc.Write(out1); * out1.Close(); * } */ }
public void TestBookmarks() { XWPFDocument doc = XWPFTestDataSamples.OpenSampleDocument("bookmarks.docx"); XWPFParagraph paragraph = doc.Paragraphs[0]; Assert.AreEqual("Sample Word Document", paragraph.Text); Assert.AreEqual(1, paragraph.GetCTP().SizeOfBookmarkStartArray()); Assert.AreEqual(0, paragraph.GetCTP().SizeOfBookmarkEndArray()); CT_Bookmark ctBookmark = paragraph.GetCTP().GetBookmarkStartArray(0); Assert.AreEqual("poi", ctBookmark.name); foreach (CT_Bookmark bookmark in paragraph.GetCTP().GetBookmarkStartList()) { Assert.AreEqual("poi", bookmark.name); } }
public void SetParagraph(XWPFParagraph p) { if (ctTc.SizeOfPArray() == 0) { ctTc.AddNewP(); } ctTc.SetPArray(0, p.GetCTP()); }
public XWPFCommentsDecorator(XWPFParagraph paragraph, XWPFParagraphDecorator nextDecorator) : base(paragraph, nextDecorator) { ; XWPFComment comment; commentText = new StringBuilder(); foreach (CT_MarkupRange anchor in paragraph.GetCTP().GetCommentRangeStartList()) { if ((comment = paragraph.Document.GetCommentByID(anchor.id)) != null) commentText.Append("\tComment by " + comment.GetAuthor() + ": " + comment.GetText()); } }
public void TestHeaderParagraph() { XWPFDocument xml = XWPFTestDataSamples.OpenSampleDocument("ThreeColHead.docx"); XWPFHeader hdr = xml.GetHeaderFooterPolicy().GetDefaultHeader(); Assert.IsNotNull(hdr); IList <XWPFParagraph> ps = hdr.Paragraphs; Assert.AreEqual(1, ps.Count); XWPFParagraph p = ps[(0)]; Assert.AreEqual(5, p.GetCTP().GetRList().Count); Assert.AreEqual("First header column!\tMid header\tRight header!", p.Text); }
public void TestSetGetPageBreak() { XWPFDocument doc = new XWPFDocument(); XWPFParagraph p = doc.CreateParagraph(); CT_P ctp = p.GetCTP(); CT_PPr ppr = ctp.pPr == null?ctp.AddNewPPr() : ctp.pPr; CT_OnOff pageBreak = ppr.AddNewPageBreakBefore(); pageBreak.val = false; Assert.AreEqual(false, p.IsPageBreak); p.IsPageBreak = (true); Assert.AreEqual(true, ppr.pageBreakBefore.val); }
public void TestSetGetWordWrap() { XWPFDocument doc = new XWPFDocument(); XWPFParagraph p = doc.CreateParagraph(); CT_P ctp = p.GetCTP(); CT_PPr ppr = ctp.pPr == null?ctp.AddNewPPr() : ctp.pPr; CT_OnOff wordWrap = ppr.AddNewWordWrap(); wordWrap.val = false; Assert.AreEqual(false, p.IsWordWrap); p.IsWordWrap = true; Assert.AreEqual(true, ppr.wordWrap.val); }
public void TestSetGetVerticalAlignment() { //new clean instance of paragraph XWPFDocument doc = new XWPFDocument(); XWPFParagraph p = doc.CreateParagraph(); CT_P ctp = p.GetCTP(); CT_PPr ppr = ctp.pPr == null?ctp.AddNewPPr() : ctp.pPr; CT_TextAlignment txtAlign = ppr.AddNewTextAlignment(); txtAlign.val = (ST_TextAlignment.center); Assert.AreEqual(TextAlignment.CENTER, p.VerticalAlignment); p.VerticalAlignment = (TextAlignment.BOTTOM); Assert.AreEqual(ST_TextAlignment.bottom, ppr.textAlignment.val); }
public void TestSetGetSpacingLineRule() { XWPFDocument doc = new XWPFDocument(); XWPFParagraph p = doc.CreateParagraph(); CT_P ctp = p.GetCTP(); CT_PPr ppr = ctp.pPr == null?ctp.AddNewPPr() : ctp.pPr; Assert.AreEqual(LineSpacingRule.AUTO, p.SpacingLineRule); CT_Spacing spacing = ppr.AddNewSpacing(); spacing.lineRule = (ST_LineSpacingRule.atLeast); Assert.AreEqual(LineSpacingRule.ATLEAST, p.SpacingLineRule); p.SpacingAfter = 100; Assert.AreEqual(100, (int)spacing.after); }
public void TestSetGetSpacing() { XWPFDocument doc = new XWPFDocument(); XWPFParagraph p = doc.CreateParagraph(); CT_P ctp = p.GetCTP(); CT_PPr ppr = ctp.pPr == null?ctp.AddNewPPr() : ctp.pPr; Assert.AreEqual(-1, p.SpacingAfter); CT_Spacing spacing = ppr.AddNewSpacing(); spacing.after = 10; Assert.AreEqual(10, p.SpacingAfter); p.SpacingAfter = 100; Assert.AreEqual(100, (int)spacing.after); }
public void TestSetAlignment() { //new clean instance of paragraph XWPFDocument doc = new XWPFDocument(); XWPFParagraph p = doc.CreateParagraph(); Assert.AreEqual(ParagraphAlignment.LEFT, p.Alignment); CT_P ctp = p.GetCTP(); CT_PPr ppr = ctp.pPr == null?ctp.AddNewPPr() : ctp.pPr; CT_Jc align = ppr.AddNewJc(); align.val = (ST_Jc.center); Assert.AreEqual(ParagraphAlignment.CENTER, p.Alignment); p.Alignment = (ParagraphAlignment.BOTH); Assert.AreEqual((int)ST_Jc.both, (int)ppr.jc.val); }
public void TestSetGetIndentation() { XWPFDocument doc = new XWPFDocument(); XWPFParagraph p = doc.CreateParagraph(); Assert.AreEqual(-1, p.IndentationLeft); CT_P ctp = p.GetCTP(); CT_PPr ppr = ctp.pPr == null?ctp.AddNewPPr() : ctp.pPr; Assert.AreEqual(-1, p.IndentationLeft); CT_Ind ind = ppr.AddNewInd(); ind.left = "10"; Assert.AreEqual(10, p.IndentationLeft); p.IndentationLeft = 100; Assert.AreEqual(100, int.Parse(ind.left)); }
public void TestSetBorderTop() { //new clean instance of paragraph XWPFDocument doc = new XWPFDocument(); XWPFParagraph p = doc.CreateParagraph(); Assert.AreEqual(ST_Border.none, EnumConverter.ValueOf <ST_Border, Borders>(p.BorderTop)); CT_P ctp = p.GetCTP(); CT_PPr ppr = ctp.pPr == null?ctp.AddNewPPr() : ctp.pPr; //bordi CT_PBdr bdr = ppr.AddNewPBdr(); CT_Border borderTop = bdr.AddNewTop(); borderTop.val = (ST_Border.@double); bdr.top = (borderTop); Assert.AreEqual(Borders.Double, p.BorderTop); p.BorderTop = (Borders.Single); Assert.AreEqual(ST_Border.single, borderTop.val); }
/** * copies content of a paragraph to a existing paragraph in the list paragraphs at position pos * @param paragraph * @param pos */ public void SetParagraph(XWPFParagraph paragraph, int pos) { paragraphs[pos]= paragraph; ctDocument.body.SetPArray(pos, paragraph.GetCTP()); /* TODO update body element, update xwpf element, verify that * incoming paragraph belongs to this document or if not, XML was * copied properly (namespace-abbreviations, etc.) */ }
public XWPFTable ConvertParagraphToTable(XWPFParagraph p, int rows, int cols) { int docpos = bodyElements.IndexOf(p); XWPFTable table = new XWPFTable(ctDocument.body.ParagraphToTable(p.GetCTP()), this, rows, cols); RemoveBodyElement(docpos); bodyElements.Insert(docpos, table); tables.Add(table); return table; }
public void SetParagraph(XWPFParagraph paragraph, int pos) { this.paragraphs[pos] = paragraph; this.ctDocument.body.SetPArray(pos, paragraph.GetCTP()); }
public void SetParagraph(XWPFParagraph p) { if (ctTc.SizeOfPArray() == 0) { ctTc.AddNewP(); } ctTc.SetPArray(0, p.GetCTP()); }
public void AppendParagraphText(StringBuilder text, XWPFParagraph paragraph) { try { CT_SectPr ctSectPr = null; if (paragraph.GetCTP().pPr != null) { ctSectPr = paragraph.GetCTP().pPr.sectPr; } XWPFHeaderFooterPolicy headerFooterPolicy = null; if (ctSectPr != null) { headerFooterPolicy = new XWPFHeaderFooterPolicy(document, ctSectPr); extractHeaders(text, headerFooterPolicy); } foreach (IRunElement run in paragraph.Runs) { text.Append(run.ToString()); if (run is XWPFHyperlinkRun && fetchHyperlinks) { XWPFHyperlink link = ((XWPFHyperlinkRun)run).GetHyperlink(document); if (link != null) text.Append(" <" + link.URL + ">"); } } // Add comments XWPFCommentsDecorator decorator = new XWPFCommentsDecorator(paragraph, null); String commentText = decorator.GetCommentText(); if (commentText.Length > 0) { text.Append(commentText).Append('\n'); } // Do endnotes and footnotes String footnameText = paragraph.FootnoteText; if (footnameText != null && footnameText.Length > 0) { text.Append(footnameText + '\n'); } if (ctSectPr != null) { extractFooters(text, headerFooterPolicy); } } catch (IOException e) { throw new POIXMLException(e); } catch (XmlException e) { throw new POIXMLException(e); } }