List<HSLFTextRun> textRuns = htp.getTextRuns(); String firstLine = removePBreak(textRuns.get(0).getRawText()); boolean showBullet = (isBullet && (textRuns.size() > 1 || !"".equals(firstLine)));
private static String collectText(List<List<HSLFTextParagraph>> paragraphs, String title) { return paragraphs.stream() .flatMap(Collection::stream) .flatMap(paragraph -> paragraph.getTextRuns().stream()) .map(HSLFTextRun::getRawText) .filter(rawText -> !title.equals(rawText)) .collect(Collectors.joining()); } }
private static String collectText(List<List<HSLFTextParagraph>> paragraphs, String title) { return paragraphs.stream() .flatMap(Collection::stream) .flatMap(paragraph -> paragraph.getTextRuns().stream()) .map(HSLFTextRun::getRawText) .filter(rawText -> !title.equals(rawText)) .collect(Collectors.joining()); } }
public static String getRawText(List<HSLFTextParagraph> paragraphs) { StringBuilder sb = new StringBuilder(); for (HSLFTextParagraph p : paragraphs) { for (HSLFTextRun r : p.getTextRuns()) { sb.append(r.getRawText()); } } return sb.toString(); }
@Override public String toString() { StringBuilder sb = new StringBuilder(); for (HSLFTextRun r : getTextRuns()) { sb.append(r.getRawText()); } return toExternalString(sb.toString(), getRunType()); }
/** * Sets (overwrites) the current text. * Uses the properties of the first paragraph / textrun * * @param text the text string used by this object. */ public static HSLFTextRun setText(List<HSLFTextParagraph> paragraphs, String text) { // check paragraphs assert(!paragraphs.isEmpty() && !paragraphs.get(0).getTextRuns().isEmpty()); Iterator<HSLFTextParagraph> paraIter = paragraphs.iterator(); HSLFTextParagraph htp = paraIter.next(); // keep first assert (htp != null); while (paraIter.hasNext()) { paraIter.next(); paraIter.remove(); } Iterator<HSLFTextRun> runIter = htp.getTextRuns().iterator(); if (runIter.hasNext()) { HSLFTextRun htr = runIter.next(); htr.setText(""); while (runIter.hasNext()) { runIter.next(); runIter.remove(); } } else { HSLFTextRun trun = new HSLFTextRun(htp); htp.addTextRun(trun); } return appendText(paragraphs, text, false); }
/** * Check and add linebreaks to text runs leading other paragraphs * * @param paragraphs */ protected static void fixLineEndings(List<HSLFTextParagraph> paragraphs) { HSLFTextRun lastRun = null; for (HSLFTextParagraph p : paragraphs) { if (lastRun != null && !lastRun.getRawText().endsWith("\r")) { lastRun.setText(lastRun.getRawText() + "\r"); } List<HSLFTextRun> ltr = p.getTextRuns(); if (ltr.isEmpty()) { throw new HSLFException("paragraph without textruns found"); } lastRun = ltr.get(ltr.size() - 1); assert (lastRun.getRawText() != null); } }
protected static void applyParagraphIndents(List<HSLFTextParagraph> paragraphs, List<IndentProp> paraStyles) { int paraIdx = 0; for (IndentProp p : paraStyles) { for (int ccPara = 0, ccStyle = p.getCharactersCovered(); ccPara < ccStyle; paraIdx++) { if (paraIdx >= paragraphs.size() || ccPara >= ccStyle-1) { return; } HSLFTextParagraph para = paragraphs.get(paraIdx); int len = 0; for (HSLFTextRun trun : para.getTextRuns()) { len += trun.getLength(); } para.setIndentLevel(p.getIndentLevel()); ccPara += len + 1; } } }
protected static void applyParagraphStyles(List<HSLFTextParagraph> paragraphs, List<TextPropCollection> paraStyles) { int paraIdx = 0; for (TextPropCollection p : paraStyles) { for (int ccPara = 0, ccStyle = p.getCharactersCovered(); ccPara < ccStyle; paraIdx++) { if (paraIdx >= paragraphs.size()) { return; } HSLFTextParagraph htp = paragraphs.get(paraIdx); TextPropCollection pCopy = new TextPropCollection(0, TextPropType.paragraph); pCopy.copy(p); htp.setParagraphStyle(pCopy); int len = 0; for (HSLFTextRun trun : htp.getTextRuns()) { len += trun.getLength(); } if (paraIdx == paragraphs.size()-1) { len++; } pCopy.updateTextSize(len); ccPara += len; } } }
assert(!paragraphs.isEmpty() && !paragraphs.get(0).getTextRuns().isEmpty()); HSLFTextRun htr = htp.getTextRuns().get(htp.getTextRuns().size() - 1); boolean lastParaEmpty = lastRunEmpty && (htp.getTextRuns().size() == 1);
for (int ccRun = 0, ccStyle = p.getCharactersCovered(); ccRun < ccStyle;) { HSLFTextParagraph para = paragraphs.get(paraIdx); List<HSLFTextRun> runs = para.getTextRuns(); trun = runs.get(runIdx); final int len = trun.getLength();
public static void main(String[] args) throws IOException { try (HSLFSlideShow ppt = new HSLFSlideShow()) { HSLFSlide slideA = ppt.createSlide(); ppt.createSlide(); HSLFSlide slideC = ppt.createSlide(); // link to a URL HSLFTextBox textBox1 = slideA.createTextBox(); textBox1.setText("Apache POI"); textBox1.setAnchor(new Rectangle(100, 100, 200, 50)); HSLFHyperlink link1 = textBox1.getTextParagraphs().get(0).getTextRuns().get(0).createHyperlink(); link1.linkToUrl("http://www.apache.org"); link1.setLabel(textBox1.getText()); // link to another slide HSLFTextBox textBox2 = slideA.createTextBox(); textBox2.setText("Go to slide #3"); textBox2.setAnchor(new Rectangle(100, 300, 200, 50)); HSLFHyperlink link2 = textBox2.getTextParagraphs().get(0).getTextRuns().get(0).createHyperlink(); link2.linkToSlide(slideC); try (FileOutputStream out = new FileOutputStream("hyperlink.ppt")) { ppt.write(out); } } } }
public static void main(String[] args) throws IOException { try (HSLFSlideShow ppt = new HSLFSlideShow()) { HSLFSlide slide = ppt.createSlide(); HSLFTextBox shape = new HSLFTextBox(); HSLFTextParagraph rt = shape.getTextParagraphs().get(0); rt.getTextRuns().get(0).setFontSize(42d); rt.setBullet(true); rt.setIndent(0d); //bullet offset rt.setLeftMargin(50d); //text offset (should be greater than bullet offset) rt.setBulletChar('\u263A'); //bullet character shape.setText( "January\r" + "February\r" + "March\r" + "April"); slide.addShape(shape); shape.setAnchor(new java.awt.Rectangle(50, 50, 500, 300)); //position of the text box in the slide slide.addShape(shape); try (FileOutputStream out = new FileOutputStream("bullets.ppt")) { ppt.write(out); } } } }
break; List<HSLFTextRun> runs = p.getTextRuns(); for (int rlen=0,rIdx=0; rIdx < runs.size(); csIdx+=rlen, rIdx++) { HSLFTextRun run = runs.get(rIdx);
for (HSLFTextRun textRun : textPara.getTextRuns()) { sb.append(textRun.getRawText()); sb.append(' ');
static void create1stTable(HSLFSlide slide) { //six rows, two columns HSLFTable table1 = slide.createTable(6, 2); for (int i = 0; i < txt1.length; i++) { for (int j = 0; j < txt1[i].length; j++) { HSLFTableCell cell = table1.getCell(i, j); HSLFTextRun rt = cell.getTextParagraphs().get(0).getTextRuns().get(0); rt.setFontFamily("Arial"); rt.setFontSize(10d); if(i == 0){ cell.getFill().setForegroundColor(new Color(227, 227, 227)); } else { rt.setBold(true); } cell.setVerticalAlignment(VerticalAlignment.MIDDLE); cell.setHorizontalCentered(true); cell.setText(txt1[i][j]); } } DrawTableShape dts1 = new DrawTableShape(table1); dts1.setAllBorders(1.0, Color.black); table1.setColumnWidth(0, 300); table1.setColumnWidth(1, 150); int pgWidth = slide.getSlideShow().getPageSize().width; table1.moveTo((pgWidth - table1.getAnchor().getWidth())/2., 100.); }
List<HSLFTextRun> textRuns = htp.getTextRuns(); String firstLine = removePBreak(textRuns.get(0).getRawText()); boolean showBullet = (isBullet && (textRuns.size() > 1 || !"".equals(firstLine)));
List<HSLFTextRun> textRuns = htp.getTextRuns(); String firstLine = removePBreak(textRuns.get(0).getRawText()); boolean showBullet = (isBullet && (textRuns.size() > 1 || !"".equals(firstLine)));
for (HSLFTextParagraph htp : _paragraphs) { int runsLen = 0; for (HSLFTextRun htr : htp.getTextRuns()) { runsLen += htr.getLength(); charStyle = sta.addCharacterTextPropCollection(htr.getLength());
for (int j = 0; j < txt2[i].length; j++) { HSLFTableCell cell = table2.getCell(i, j); HSLFTextRun rt = cell.getTextParagraphs().get(0).getTextRuns().get(0); rt.setFontSize(10d); rt.setFontFamily("Arial");