Java Code Examples for org.apache.poi.xwpf.usermodel.XWPFParagraph#getRuns()
The following examples show how to use
org.apache.poi.xwpf.usermodel.XWPFParagraph#getRuns() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: M2DocTestUtils.java From M2Doc with Eclipse Public License 1.0 | 5 votes |
/** * Gets the {@link XWPFRun} containing the given text in the given {@link XWPFDocument}. * * @param document * the {@link XWPFDocument} * @param text * the {@link XWPFRun} * @return the {@link XWPFRun} containing the given text in the given {@link XWPFDocument} if any, <code>null</code> otherwise */ public static XWPFRun getRunContaining(XWPFDocument document, String text) { XWPFRun res = null; for (XWPFParagraph paragraph : document.getParagraphs()) { for (XWPFRun run : paragraph.getRuns()) { if (run.text().contains(text)) { res = run; break; } } } return res; }
Example 2
Source File: IterableProcessor.java From poi-tl with Apache License 2.0 | 5 votes |
@Override protected void handleNever(IterableTemplate iterableTemplate, BodyContainer bodyContainer) { XWPFParagraph startParagraph = (XWPFParagraph) iterableTemplate.getStartRun().getParent(); XWPFParagraph endParagraph = (XWPFParagraph) iterableTemplate.getEndRun().getParent(); int startPos = bodyContainer.getPosOfParagraphCTP(startParagraph.getCTP()); int endPos = bodyContainer.getPosOfParagraphCTP(endParagraph.getCTP()); // remove content for (int i = endPos - 1; i > startPos; i--) { bodyContainer.removeBodyElement(i); } XWPFParagraphWrapper startParagraphWrapper = new XWPFParagraphWrapper(startParagraph); XWPFParagraphWrapper endParagraphWrapper = new XWPFParagraphWrapper(endParagraph); Integer startRunPos = iterableTemplate.getStartMark().getRunPos(); Integer endRunPos = iterableTemplate.getEndMark().getRunPos(); // remove run content List<XWPFRun> startRuns = startParagraph.getRuns(); int startSize = startRuns.size(); for (int i = startSize - 1; i > startRunPos; i--) { startParagraphWrapper.removeRun(i); } for (int i = endRunPos - 1; i >= 0; i--) { endParagraphWrapper.removeRun(i); } }
Example 3
Source File: RunTemplate.java From poi-tl with Apache License 2.0 | 5 votes |
public Integer getRunPos() { XWPFParagraph paragraph = (XWPFParagraph) run.getParent(); List<XWPFRun> runs = paragraph.getRuns(); for (int i = 0; i < runs.size(); i++) { if (run == runs.get(i)) { return i; } } return null; }
Example 4
Source File: RunningRunParagraph.java From poi-tl with Apache License 2.0 | 5 votes |
public RunningRunParagraph(XWPFParagraph paragraph, Pattern pattern) { this.paragraph = paragraph; this.runs = paragraph.getRuns(); if (null == runs || runs.isEmpty()) return; Matcher matcher = pattern.matcher(paragraph.getText()); if (matcher.find()) { refactorParagraph(); } buildRunEdge(pattern); }