List of usage examples for org.apache.poi.xwpf.usermodel XWPFRun addBreak
public void addBreak(BreakClear clear)
From source file:org.eclipse.sw360.licenseinfo.outputGenerators.DocxUtils.java
License:Open Source License
public static void addNewLines(XWPFRun run, int numberOfNewlines) { for (int count = 0; count < numberOfNewlines; count++) { run.addCarriageReturn();//from w w w.j ava 2 s . co m run.addBreak(BreakType.TEXT_WRAPPING); } }
From source file:org.eclipse.sw360.licenseinfo.outputGenerators.DocxUtils.java
License:Open Source License
public static void addPageBreak(XWPFDocument document) { XWPFParagraph paragraph = document.createParagraph(); XWPFRun run = paragraph.createRun(); run.addBreak(BreakType.TEXT_WRAPPING); run.addBreak(BreakType.PAGE);//from ww w . j a v a 2 s . c o m }
From source file:org.obeonetwork.m2doc.generator.M2DocEvaluator.java
License:Open Source License
/** * Insert the given {@link MPagination}. * // w w w . ja va 2 s . c om * @param run * the {@link XWPFRun} to insert to * @param mPagination * the {@link MPagination} */ private void insertMPagination(XWPFRun run, MPagination mPagination) { switch (mPagination) { case newColumn: run.addBreak(BreakType.COLUMN); break; case newParagraph: createNewParagraph((XWPFParagraph) run.getParent()); break; case newPage: run.addBreak(BreakType.PAGE); break; case newTableOfContent: CTP ctP = currentGeneratedParagraph.getCTP(); CTSimpleField toc = ctP.addNewFldSimple(); toc.setInstr("TOC \\h"); toc.setDirty(STOnOff.TRUE); break; case newTextWrapping: run.addBreak(BreakType.TEXT_WRAPPING); break; default: throw new IllegalStateException("Not supported MPagination."); } }
From source file:org.ohdsi.rabbitInAHat.ETLDocumentGenerator.java
License:Apache License
private static void addSourceTablesAppendix(CustomXWPFDocument document, ETL etl) { XWPFParagraph paragraph = document.createParagraph(); XWPFRun run = paragraph.createRun(); run.addBreak(BreakType.PAGE); run.setText("Appendix: source tables"); run.setFontSize(18);// w w w . j a va 2 s.c o m for (Table sourceTable : etl.getSourceDatabase().getTables()) { paragraph = document.createParagraph(); run = paragraph.createRun(); run.setText("Table: " + sourceTable.getName()); run.setFontSize(14); createDocumentParagraph(document, sourceTable.getComment()); XWPFTable table = document.createTable(sourceTable.getFields().size() + 1, 4); // table.setWidth(2000); XWPFTableRow header = table.getRow(0); setTextAndHeaderShading(header.getCell(0), "Field"); setTextAndHeaderShading(header.getCell(1), "Type"); setTextAndHeaderShading(header.getCell(2), "Most freq. value"); setTextAndHeaderShading(header.getCell(3), "Comment"); int rowNr = 1; for (Field sourceField : sourceTable.getFields()) { XWPFTableRow row = table.getRow(rowNr++); row.getCell(0).setText(sourceField.getName()); row.getCell(1).setText(sourceField.getType().toString()); if (sourceField.getValueCounts() != null && sourceField.getValueCounts().length != 0) row.getCell(2).setText(sourceField.getValueCounts()[0][0]); createCellParagraph(row.getCell(3), sourceField.getComment().trim()); } } run.setFontSize(18); }
From source file:org.ohdsi.rabbitInAHat.ETLDocumentGenerator.java
License:Apache License
private static void addTargetTableSection(CustomXWPFDocument document, ETL etl, Table targetTable) throws InvalidFormatException, FileNotFoundException { XWPFParagraph paragraph = document.createParagraph(); XWPFRun run = paragraph.createRun(); run.addBreak(BreakType.PAGE); run.setText("Table name: " + targetTable.getName()); run.setFontSize(18);/*from www .j av a2s . c o m*/ createDocumentParagraph(document, targetTable.getComment()); for (ItemToItemMap tableToTableMap : etl.getTableToTableMapping().getSourceToTargetMaps()) if (tableToTableMap.getTargetItem() == targetTable) { Table sourceTable = (Table) tableToTableMap.getSourceItem(); Mapping<Field> fieldtoFieldMapping = etl.getFieldToFieldMapping(sourceTable, targetTable); paragraph = document.createParagraph(); run = paragraph.createRun(); run.setText("Reading from " + tableToTableMap.getSourceItem()); run.setFontSize(14); createDocumentParagraph(document, tableToTableMap.getLogic()); createDocumentParagraph(document, tableToTableMap.getComment()); // Add picture of field to field mapping MappingPanel mappingPanel = new MappingPanel(fieldtoFieldMapping); mappingPanel.setShowOnlyConnectedItems(true); int height = mappingPanel.getMinimumSize().height; mappingPanel.setSize(800, height); BufferedImage im = new BufferedImage(800, height, BufferedImage.TYPE_INT_ARGB); im.getGraphics().setColor(Color.WHITE); im.getGraphics().fillRect(0, 0, im.getWidth(), im.getHeight()); mappingPanel.paint(im.getGraphics()); document.addPicture(im, 600, height * 6 / 8); // Add table of field to field mapping XWPFTable table = document.createTable(fieldtoFieldMapping.getTargetItems().size() + 1, 4); // table.setWidth(2000); XWPFTableRow header = table.getRow(0); setTextAndHeaderShading(header.getCell(0), "Destination Field"); setTextAndHeaderShading(header.getCell(1), "Source Field"); setTextAndHeaderShading(header.getCell(2), "Logic"); setTextAndHeaderShading(header.getCell(3), "Comment"); int rowNr = 1; for (MappableItem targetField : fieldtoFieldMapping.getTargetItems()) { XWPFTableRow row = table.getRow(rowNr++); row.getCell(0).setText(targetField.getName()); StringBuilder source = new StringBuilder(); StringBuilder logic = new StringBuilder(); StringBuilder comment = new StringBuilder(); for (ItemToItemMap fieldToFieldMap : fieldtoFieldMapping.getSourceToTargetMaps()) { if (fieldToFieldMap.getTargetItem() == targetField) { if (source.length() != 0) source.append("\n"); source.append(fieldToFieldMap.getSourceItem().getName().trim()); if (logic.length() != 0) logic.append("\n"); logic.append(fieldToFieldMap.getLogic().trim()); if (comment.length() != 0) comment.append("\n"); comment.append(fieldToFieldMap.getComment().trim()); } } for (Field field : targetTable.getFields()) { if (field.getName().equals(targetField.getName())) { if (comment.length() != 0) comment.append("\n"); comment.append(field.getComment().trim()); } } createCellParagraph(row.getCell(1), source.toString()); createCellParagraph(row.getCell(2), logic.toString()); createCellParagraph(row.getCell(3), comment.toString()); } } }
From source file:org.robert.study.service.merge.doc.SimpleDocument.java
License:Apache License
public static void main(String[] args) throws Exception { XWPFDocument doc = new XWPFDocument(); XWPFParagraph p1 = doc.createParagraph(); p1.setAlignment(ParagraphAlignment.CENTER); p1.setBorderBottom(Borders.DOUBLE);// w ww .j ava 2s . c o m p1.setBorderTop(Borders.DOUBLE); p1.setBorderRight(Borders.DOUBLE); p1.setBorderLeft(Borders.DOUBLE); p1.setBorderBetween(Borders.SINGLE); p1.setVerticalAlignment(TextAlignment.TOP); XWPFRun r1 = p1.createRun(); r1.setBold(true); r1.setText("The quick brown fox"); r1.setBold(true); r1.setFontFamily("Courier"); r1.setUnderline(UnderlinePatterns.DOT_DOT_DASH); r1.setTextPosition(100); XWPFParagraph p2 = doc.createParagraph(); p2.setAlignment(ParagraphAlignment.RIGHT); // BORDERS p2.setBorderBottom(Borders.DOUBLE); p2.setBorderTop(Borders.DOUBLE); p2.setBorderRight(Borders.DOUBLE); p2.setBorderLeft(Borders.DOUBLE); p2.setBorderBetween(Borders.SINGLE); XWPFRun r2 = p2.createRun(); r2.setText("jumped over the lazy dog"); r2.setStrike(true); r2.setFontSize(20); XWPFRun r3 = p2.createRun(); r3.setText("and went away"); r3.setStrike(true); r3.setFontSize(20); r3.setSubscript(VerticalAlign.SUPERSCRIPT); XWPFParagraph p3 = doc.createParagraph(); p3.setWordWrap(true); p3.setPageBreak(true); // p3.setAlignment(ParagraphAlignment.DISTRIBUTE); p3.setAlignment(ParagraphAlignment.BOTH); p3.setSpacingLineRule(LineSpacingRule.EXACT); p3.setIndentationFirstLine(600); XWPFRun r4 = p3.createRun(); r4.setTextPosition(20); r4.setText("To be, or not to be: that is the question: " + "Whether 'tis nobler in the mind to suffer " + "The slings and arrows of outrageous fortune, " + "Or to take arms against a sea of troubles, " + "And by opposing end them? To die: to sleep; "); r4.addBreak(BreakType.PAGE); r4.setText("No more; and by a sleep to say we end " + "The heart-ache and the thousand natural shocks " + "That flesh is heir to, 'tis a consummation " + "Devoutly to be wish'd. To die, to sleep; " + "To sleep: perchance to dream: ay, there's the rub; " + "......."); r4.setItalic(true); // This would imply that this break shall be treated as a simple line // break, and break the line after that word: XWPFRun r5 = p3.createRun(); r5.setTextPosition(-10); r5.setText("For in that sleep of death what dreams may come"); r5.addCarriageReturn(); r5.setText("When we have shuffled off this mortal coil," + "Must give us pause: there's the respect" + "That makes calamity of so long life;"); r5.addBreak(); r5.setText("For who would bear the whips and scorns of time," + "The oppressor's wrong, the proud man's contumely,"); r5.addBreak(BreakClear.ALL); r5.setText("The pangs of despised love, the law's delay," + "The insolence of office and the spurns" + "......."); FileOutputStream out = new FileOutputStream("z://simple.docx"); doc.write(out); out.close(); }
From source file:ParserDoc.SimpleDocument.java
License:Apache License
public static void main(String[] args) throws Exception { XWPFDocument doc = new XWPFDocument(); XWPFParagraph p1 = doc.createParagraph(); p1.setAlignment(ParagraphAlignment.CENTER); p1.setBorderBottom(Borders.DOUBLE);//from ww w.ja v a2 s. c o m p1.setBorderTop(Borders.DOUBLE); p1.setBorderRight(Borders.DOUBLE); p1.setBorderLeft(Borders.DOUBLE); p1.setBorderBetween(Borders.SINGLE); p1.setVerticalAlignment(TextAlignment.TOP); XWPFRun r1 = p1.createRun(); r1.setBold(true); r1.setText("The quick brown fox"); r1.setBold(true); r1.setFontFamily("Courier"); r1.setUnderline(UnderlinePatterns.DOT_DOT_DASH); r1.setTextPosition(100); XWPFParagraph p2 = doc.createParagraph(); p2.setAlignment(ParagraphAlignment.RIGHT); //BORDERS p2.setBorderBottom(Borders.DOUBLE); p2.setBorderTop(Borders.DOUBLE); p2.setBorderRight(Borders.DOUBLE); p2.setBorderLeft(Borders.DOUBLE); p2.setBorderBetween(Borders.SINGLE); XWPFRun r2 = p2.createRun(); r2.setText("jumped over the lazy dog"); // r2.setStrikeThrough(true); r2.setFontSize(20); XWPFRun r3 = p2.createRun(); r3.setText("and went away"); // r3.setStrikeThrough(true); r3.setFontSize(20); r3.setSubscript(VerticalAlign.SUPERSCRIPT); XWPFParagraph p3 = doc.createParagraph(); // p3.setWordWrapped(true); p3.setPageBreak(true); //p3.setAlignment(ParagraphAlignment.DISTRIBUTE); p3.setAlignment(ParagraphAlignment.BOTH); // p3.setSpacingBetween(15, LineSpacingRule.EXACT); p3.setIndentationFirstLine(600); XWPFRun r4 = p3.createRun(); r4.setTextPosition(20); r4.setText("To be, or not to be: that is the question: " + "Whether 'tis nobler in the mind to suffer " + "The slings and arrows of outrageous fortune, " + "Or to take arms against a sea of troubles, " + "And by opposing end them? To die: to sleep; "); r4.addBreak(BreakType.PAGE); r4.setText("No more; and by a sleep to say we end " + "The heart-ache and the thousand natural shocks " + "That flesh is heir to, 'tis a consummation " + "Devoutly to be wish'd. To die, to sleep; " + "To sleep: perchance to dream: ay, there's the rub; " + "......."); r4.setItalic(true); //This would imply that this break shall be treated as a simple line break, and break the line after that word: XWPFRun r5 = p3.createRun(); r5.setTextPosition(-10); r5.setText("For in that sleep of death what dreams may come"); r5.addCarriageReturn(); r5.setText("When we have shuffled off this mortal coil," + "Must give us pause: there's the respect" + "That makes calamity of so long life;"); r5.addBreak(); r5.setText("For who would bear the whips and scorns of time," + "The oppressor's wrong, the proud man's contumely,"); r5.addBreak(BreakClear.ALL); r5.setText("The pangs of despised love, the law's delay," + "The insolence of office and the spurns" + "......."); FileOutputStream out = new FileOutputStream("simple.docx"); doc.write(out); out.close(); // out.close (); }
From source file:ro.dabuno.office.integration.SimpleDocument.java
License:Apache License
public static void main(String[] args) throws Exception { XWPFDocument doc = new XWPFDocument(); XWPFParagraph p0 = doc.createParagraph(); XWPFRun r0 = p0.createRun();/* w w w.java2s . c om*/ r0.setBold(false); r0.setText("Domnule"); XWPFRun r00 = p0.createRun(); r00.setBold(true); r00.setText(" Ionescu Ion"); XWPFParagraph p1 = doc.createParagraph(); p1.setAlignment(ParagraphAlignment.CENTER); p1.setBorderBottom(Borders.DOUBLE); p1.setBorderTop(Borders.DOUBLE); p1.setBorderRight(Borders.DOUBLE); p1.setBorderLeft(Borders.DOUBLE); p1.setBorderBetween(Borders.SINGLE); p1.setVerticalAlignment(TextAlignment.TOP); XWPFRun r1 = p1.createRun(); r1.setBold(true); r1.setText("The quick brown fox"); r1.setBold(true); r1.setFontFamily("Courier"); r1.setUnderline(UnderlinePatterns.DOT_DOT_DASH); r1.setTextPosition(100); XWPFParagraph p2 = doc.createParagraph(); p2.setAlignment(ParagraphAlignment.RIGHT); //BORDERS p2.setBorderBottom(Borders.DOUBLE); p2.setBorderTop(Borders.DOUBLE); p2.setBorderRight(Borders.DOUBLE); p2.setBorderLeft(Borders.DOUBLE); p2.setBorderBetween(Borders.SINGLE); XWPFRun r2 = p2.createRun(); r2.setText("jumped over the lazy dog"); r2.setStrike(true); r2.setFontSize(20); XWPFRun r3 = p2.createRun(); r3.setText("and went away"); r3.setStrike(true); r3.setFontSize(20); r3.setSubscript(VerticalAlign.SUPERSCRIPT); XWPFParagraph p3 = doc.createParagraph(); p3.setWordWrap(true); p3.setPageBreak(true); //p3.setAlignment(ParagraphAlignment.DISTRIBUTE); p3.setAlignment(ParagraphAlignment.BOTH); p3.setSpacingLineRule(LineSpacingRule.EXACT); p3.setIndentationFirstLine(600); XWPFRun r4 = p3.createRun(); r4.setTextPosition(20); r4.setText("To be, or not to be: that is the question: " + "Whether 'tis nobler in the mind to suffer " + "The slings and arrows of outrageous fortune, " + "Or to take arms against a sea of troubles, " + "And by opposing end them? To die: to sleep; "); r4.addBreak(BreakType.PAGE); r4.setText("No more; and by a sleep to say we end " + "The heart-ache and the thousand natural shocks " + "That flesh is heir to, 'tis a consummation " + "Devoutly to be wish'd. To die, to sleep; " + "To sleep: perchance to dream: ay, there's the rub; " + "......."); r4.setItalic(true); //This would imply that this break shall be treated as a simple line break, and break the line after that word: XWPFRun r5 = p3.createRun(); r5.setTextPosition(-10); r5.setText("For in that sleep of death what dreams may come"); r5.addCarriageReturn(); r5.setText("When we have shuffled off this mortal coil," + "Must give us pause: there's the respect" + "That makes calamity of so long life;"); r5.addBreak(); r5.setText("For who would bear the whips and scorns of time," + "The oppressor's wrong, the proud man's contumely,"); r5.addBreak(BreakClear.ALL); r5.setText("The pangs of despised love, the law's delay," + "The insolence of office and the spurns" + "......."); FileOutputStream out = new FileOutputStream("simple.docx"); doc.write(out); out.close(); }
From source file:Utils.FileHandler.java
private void pageBreak(XWPFParagraph paragraph) { XWPFRun r = paragraph.createRun(); r.addBreak(BreakType.PAGE); }