XWPFDocument document = new XWPFDocument(); XWPFParagraph tmpParagraph = document.createParagraph(); XWPFRun tmpRun = tmpParagraph.createRun(); tmpRun.setText("LALALALAALALAAAA"); tmpRun.setFontSize(18); document.write(new FileOutputStream(new File("yourpathhere"))); document.close();
public void setText(String text) { CTP ctP = (ctTc.sizeOfPArray() == 0) ? ctTc.addNewP() : ctTc.getPArray(0); XWPFParagraph par = new XWPFParagraph(ctP, this); par.createRun().setText(text); }
/** * 增加一个段落 * * @param align 段落对齐方式{@link ParagraphAlignment} * @param font 字体信息{@link Font} * @param texts 段落中的文本,支持多个文本作为一个段落 * @return this */ public Word07Writer addText(ParagraphAlignment align, Font font, String... texts) { final XWPFParagraph p = this.doc.createParagraph(); if (null != align) { p.setAlignment(align); } if (ArrayUtil.isNotEmpty(texts)) { XWPFRun run; for (String text : texts) { run = p.createRun(); run.setText(text); if (null != font) { run.setFontFamily(font.getFamily()); run.setFontSize(font.getSize()); run.setBold(font.isBold()); run.setItalic(font.isItalic()); } } } return this; }
/** * 增加一个段落 * * @param align 段落对齐方式{@link ParagraphAlignment} * @param font 字体信息{@link Font} * @param texts 段落中的文本,支持多个文本作为一个段落 * @return this */ public Word07Writer addText(ParagraphAlignment align, Font font, String... texts) { final XWPFParagraph p = this.doc.createParagraph(); if (null != align) { p.setAlignment(align); } if (ArrayUtil.isNotEmpty(texts)) { XWPFRun run; for (String text : texts) { run = p.createRun(); run.setText(text); if (null != font) { run.setFontFamily(font.getFamily()); run.setFontSize(font.getSize()); run.setBold(font.isBold()); run.setItalic(font.isItalic()); } } } return this; }
/** * This method is used to create template for chart XML * no need to read MS-Word file and modify charts * * @param width width of chart in document * @param height height of chart in document * @return This method return object of XWPFChart * @throws InvalidFormatException * @throws IOException * @since POI 4.0.0 */ public XWPFChart createChart(int width, int height) throws InvalidFormatException, IOException { //get chart number int chartNumber = getNextPartNumber(XWPFRelation.CHART, charts.size() + 1); //create relationship in document for new chart RelationPart rp = createRelationship( XWPFRelation.CHART, XWPFFactory.getInstance(), chartNumber, false); // initialize xwpfchart object XWPFChart xwpfChart = rp.getDocumentPart(); xwpfChart.setChartIndex(chartNumber); xwpfChart.attach(rp.getRelationship().getId(), createParagraph().createRun()); xwpfChart.setChartBoundingBox(width, height); //add chart object to chart list charts.add(xwpfChart); return xwpfChart; }
/** * Add a new run with a reference to the specified footnote. * The footnote reference run will have the style name "FootnoteReference". * * @param footnote Footnote to which to add a reference. * @since 4.0.0 */ public void addFootnoteReference(XWPFAbstractFootnoteEndnote footnote) { XWPFRun run = createRun(); CTR ctRun = run.getCTR(); ctRun.addNewRPr().addNewRStyle().setVal("FootnoteReference"); if (footnote instanceof XWPFEndnote) { ctRun.addNewEndnoteReference().setId(footnote.getId()); } else { ctRun.addNewFootnoteReference().setId(footnote.getId()); } } }
@Deprecated public void createPicture(String blipId, int id, int width, int height) { addPicture(blipId, id, width, height, createParagraph().createRun()); }
run = par.createRun(); StyleUtils.styleRun(run, cellData.getStyle()); run.setText(fragment[j]);
XWPFRun run = paragraph.createRun(); run.setFontSize(0); run.addBreak(BreakType.PAGE);
run=runs.get(0); }else{ run=para.createRun();
XWPFDocument document = new XWPFDocument(is); ... XWPFParagraph paragraph = document.createParagraph(); XWPFRun run = paragraph.createRun(); run.addBreak(BreakType.PAGE);
CTParaRPr pr = pPr.isSetRPr() ? pPr.getRPr() : pPr.addNewRPr(); StyleUtils.styleRpr(pr, fmtStyle); newRun = paragraph.createRun(); StyleUtils.styleRun(newRun, line.getStyle()); newRun.setText(line.getText());
XWPFDocument document = new XWPFDocument(PoiTest.class.getResourceAsStream("twocolumn.docx")); XWPFParagraph tmpParagraph = document.getParagraphs().get(0); for (int i = 0; i < 100; i++) { XWPFRun tmpRun = tmpParagraph.createRun(); tmpRun.setText("LALALALAALALAAAA"); tmpRun.setFontSize(18); } document.write(new FileOutputStream(new File("C:\\temp\\poi.docx")));
String text=list.get(i); if(text.equals("$[PAGE]")){ r1 = para.createRun(); CTFldChar fldChar = r1.getCTR().addNewFldChar(); fldChar.setFldCharType(STFldCharType.Enum.forString("begin")); fldChar.setFldCharType(STFldCharType.Enum.forString("end")); }else if(text.equals("$[PAGES]")){ r1 = para.createRun(); CTFldChar fldChar = r1.getCTR().addNewFldChar(); fldChar.setFldCharType(STFldCharType.Enum.forString("begin")); fldChar.setFldCharType(STFldCharType.Enum.forString("end")); }else if(text.equals("$[DATE]")){ r1 = para.createRun(); r1.setText(date); if(hf.getFontSize()>1){ r1 = para.createRun(); r1.setText(time); if(hf.getFontSize()>1){ r1 = para.createRun(); r1.setText(text); if(hf.getFontSize()>1){ String text=list.get(i); if(text.equals("$[PAGE]")){ r1 = para.createRun();
XWPFParagraph p1 = doc.createParagraph(); XWPFRun r1 = p1.createRun(); r1.setText("This is line one"); r1.addCarriageReturn(); r1.setText("This is line two");
private void setCellValue(XWPFTableRow row, Object value, int cellNum) { if (row.getCell(cellNum++) != null) { row.getCell(cellNum - 1).setText(value == null ? "" : value.toString()); PoiPublicUtil.setWordText(row.createCell().addParagraph().createRun(), value == null ? "" : value.toString()); } else { PoiPublicUtil.setWordText(row.createCell().addParagraph().createRun(), value == null ? "" : value.toString()); } }
XWPFDocument template = new XWPFDocument(new FileInputStream(new File("Template.dotx"))); XWPFDocument doc = new XWPFDocument(); // let's copy styles from template to new doc XWPFStyles newStyles = doc.createStyles(); newStyles.setStyles(template.getStyle()); XWPFParagraph para = doc.createParagraph(); para.setStyle("Heading1"); XWPFRun run = para.createRun(); run.setText("Heading 1"); return doc;
public void setText(String text) { CTP ctP = (ctTc.sizeOfPArray() == 0) ? ctTc.addNewP() : ctTc.getPArray(0); XWPFParagraph par = new XWPFParagraph(ctP, this); par.createRun().setText(text); }