Example usage for org.apache.poi.xwpf.usermodel XWPFParagraph createRun

List of usage examples for org.apache.poi.xwpf.usermodel XWPFParagraph createRun

Introduction

In this page you can find the example usage for org.apache.poi.xwpf.usermodel XWPFParagraph createRun.

Prototype

public XWPFRun createRun() 

Source Link

Document

Appends a new run to this paragraph

Usage

From source file:pqm.client.DocGenerator.java

public static void gerar_influencias(XWPFDocument document) {
    XWPFParagraph paragraph = document.createParagraph();
    XWPFRun run = paragraph.createRun();
    run.setText("INFLUENCIAS DOMINANTES:");
    paragraph = document.createParagraph();
    run = paragraph.createRun();/*ww  w  .ja  va 2 s  .co m*/
    run.setText("Relacoes Ascendentes: ");
    paragraph = document.createParagraph();
    run = paragraph.createRun();
    for (int i = 0; i < pqm.influenciasDominantes.relacoesAscendentes.size(); i++) {
        run.setText(pqm.influenciasDominantes.relacoesAscendentes.get(i).texto);
        paragraph = document.createParagraph();
        run = paragraph.createRun();
    }

    run.setText("Relacoes Equivalentes:");
    for (int i = 0; i < pqm.influenciasDominantes.relacoesEquivalentes.size(); i++) {
        run.setText(pqm.influenciasDominantes.relacoesEquivalentes.get(i).texto);
        paragraph = document.createParagraph();
        run = paragraph.createRun();
    }

    run.setText("Relacoes Externas");
    for (int i = 0; i < pqm.influenciasDominantes.relacoesExternas.size(); i++) {
        run.setText(pqm.influenciasDominantes.relacoesExternas.get(i).texto);
        paragraph = document.createParagraph();
        run = paragraph.createRun();
    }

    run.setText("Controlo Funcional: ");
    for (int i = 0; i < pqm.influenciasDominantes.controloFuncional.size(); i++) {
        run.setText(pqm.influenciasDominantes.controloFuncional.get(i).texto);
        paragraph = document.createParagraph();
        run = paragraph.createRun();
    }
}

From source file:pqm.client.DocGenerator.java

public static void gerar_fcs(XWPFDocument document) {
    XWPFParagraph paragraph = document.createParagraph();
    XWPFRun run = paragraph.createRun();
    run.setText("FACTORES CRITICOS DE SUCESSO:");
    paragraph = document.createParagraph();
    run = paragraph.createRun();/*w  ww  .ja v  a2 s  .co  m*/
    for (int i = 0; i < pqm.fcs.size(); i++) {
        run.setText(pqm.fcs.get(i).texto);
        paragraph = document.createParagraph();
        run = paragraph.createRun();
    }
}

From source file:pqm.client.DocGenerator.java

public static void gerar_pn(XWPFDocument document) {
    XWPFParagraph paragraph = document.createParagraph();
    XWPFRun run = paragraph.createRun();
    run.setText("PROCESSOS DE NEGOCIO:");
    paragraph = document.createParagraph();
    run = paragraph.createRun();/*from w w w. j av  a  2s .  co  m*/
    for (int i = 0; i < pqm.processosNegocio.processos.size(); i++) {
        run.setText(
                pqm.processosNegocio.processos.get(i).id + " - " + pqm.processosNegocio.processos.get(i).texto);
        paragraph = document.createParagraph();
        run = paragraph.createRun();
    }
}

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();
    r0.setBold(false);//from ww  w. ja  v a2 s  .com
    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:ro.dabuno.office.integration.Xlsx2Word.java

public static void main(String[] args) throws Exception {
    log.info("starting app");
    //        Workbook wb = new XSSFWorkbook(new FileInputStream(args[0]));
    Workbook wb = new XSSFWorkbook(new FileInputStream("office-files/Input.xlsx"));

    DataFormatter formatter = new DataFormatter();

    for (int i = 0; i < wb.getNumberOfSheets(); i++) {
        Sheet sheet = wb.getSheetAt(i);/*from  ww  w .  j  a v  a 2s .  c o  m*/
        System.out.println(wb.getSheetName(i));
        int j = 4;
        for (Row row : sheet) {
            System.out.println("rownum: " + row.getRowNum());
            for (Cell cell : row) {
                CellReference cellRef = new CellReference(row.getRowNum(), cell.getColumnIndex());
                System.out.print(cellRef.formatAsString());
                System.out.print(" - ");
                // get the text that appears in the cell by getting the cell value and applying any data formats (Date, 0.00, 1.23e9, $1.23, etc)
                String text = formatter.formatCellValue(cell);
                System.out.println(text);

                System.out.println("------------");
                // Alternatively, get the value and format it yourself
                switch (cell.getCellTypeEnum()) {
                case STRING:
                    System.out.println(cell.getRichStringCellValue().getString());
                    break;
                case NUMERIC:
                    if (DateUtil.isCellDateFormatted(cell)) {
                        System.out.println(cell.getDateCellValue());
                    } else {
                        System.out.print(cellRef.formatAsString());
                        System.out.print(" - ");
                        System.out.println((long) cell.getNumericCellValue());
                    }
                    break;
                case BOOLEAN:
                    System.out.println(cell.getBooleanCellValue());
                    break;
                case FORMULA:
                    System.out.println(cell.getCellFormula());
                    break;
                case BLANK:
                    System.out.println();
                    break;
                default:
                    System.out.println();
                }

            }
            j--;
            if (j == 0) {
                break;
            }
        }
    }

    XWPFDocument doc = new XWPFDocument();

    XWPFParagraph p0 = doc.createParagraph();
    XWPFRun r0 = p0.createRun();
    r0.setBold(false);
    r0.setText("Domnule");
    XWPFRun r00 = p0.createRun();
    r00.setBold(true);
    r00.setText(" Ionescu Ion");

    FileOutputStream out = new FileOutputStream("out/xlsx2word.docx");
    doc.write(out);
    out.close();
}

From source file:ru.ksu.niimm.cll.mocassin.rdf.ontology.util.OntologyReportGenerator.java

License:Open Source License

private static void addProperties(XWPFDocument wordDocument, OntClass ontClass) {
    Set<OntClass> equivalentClasses = ontClass.listEquivalentClasses().toSet();
    if (equivalentClasses.isEmpty())
        return;//from  www.ja  va 2s.com
    XWPFParagraph paragraph = wordDocument.createParagraph();
    paragraph.setStyle("style0");
    XWPFRun run = paragraph.createRun();
    run.setText("?: ");

    for (OntClass equivalentClass : equivalentClasses) {
        if (!equivalentClass.isRestriction())
            continue;
        AllValuesFromRestriction restriction = equivalentClass.asRestriction().asAllValuesFromRestriction();
        XWPFParagraph p = wordDocument.createParagraph();
        p.setIndentationLeft(1440);
        XWPFRun r = p.createRun();
        OntProperty onProperty = restriction.getOnProperty();
        OntClass toClass = restriction.getAllValuesFrom().as(OntClass.class);

        r.setText(format("%s: %s", formatPropertyURI(onProperty), formatURI(toClass)));
        r.setItalic(true);
    }
    wordDocument.createParagraph().setIndentationLeft(1440);
}

From source file:ru.ksu.niimm.cll.mocassin.rdf.ontology.util.OntologyReportGenerator.java

License:Open Source License

private static void addComment(XWPFDocument wordDocument, OntClass ontClass) {
    String comment = null;//  w w w  .  ja v a2  s  .  com
    if (ontClass.getComment(RU_LOCALE) != null) {
        comment = ontClass.getComment(RU_LOCALE);
    } else if (ontClass.getComment(EN_LOCALE) != null) {
        comment = ontClass.getComment(EN_LOCALE);
    } else {
        comment = ontClass.getComment(null);
    }
    if (comment == null || comment.isEmpty()) {
        classesWithEmptyComments.add(formatURI(ontClass));
        return;
    }
    XWPFParagraph paragraph = wordDocument.createParagraph();
    paragraph.setStyle("style0");
    XWPFRun run = paragraph.createRun();
    run.setText(format("?: \n%s",
            comment != null ? comment.replace("http://", ". http://").replace("www.", ". www.") : ""));
}

From source file:ru.ksu.niimm.cll.mocassin.rdf.ontology.util.OntologyReportGenerator.java

License:Open Source License

private static void addNeighbourClasses(XWPFDocument wordDocument, Set<OntClass> classes, String header) {
    if (classes.isEmpty())
        return;/* w w  w  . j  av a 2  s  . c  o m*/
    XWPFParagraph paragraph = wordDocument.createParagraph();
    paragraph.setStyle("style0");
    XWPFRun run = paragraph.createRun();
    run.setText(header);
    StringBuilder sb = new StringBuilder();
    List<OntClass> classList = new ArrayList<OntClass>(classes);
    Collections.sort(classList, new OntClassByLabelComparatorAsc());
    Iterator<OntClass> it = classList.iterator();
    while (it.hasNext()) {
        OntClass clazz = it.next();
        sb.append(formatURI(clazz));
        if (it.hasNext()) {
            sb.append("; ");
        }
    }
    XWPFParagraph p = wordDocument.createParagraph();
    p.setIndentationLeft(1440);
    XWPFRun r = p.createRun();
    r.setText(sb.toString());
    r.setItalic(true);
    wordDocument.createParagraph().setIndentationLeft(1440);
}

From source file:ru.ksu.niimm.cll.mocassin.rdf.ontology.util.OntologyReportGenerator.java

License:Open Source License

private static void addURI(XWPFDocument wordDocument, OntClass ontClass) {
    XWPFParagraph paragraph = wordDocument.createParagraph();
    paragraph.setSpacingBefore(10);//from  ww  w  .ja va 2  s  .  c o  m
    paragraph.setStyle("Heading 5");
    XWPFRun run = paragraph.createRun();
    run.setText(formatURI(ontClass));
}

From source file:service.Read_Write_File.java

public void SetDOCX_DT(List<Bordereau> bordereaus, List<CorpDetat> corpDetats, List<ArticleChp1> articlechp1s,
        List<ArticleChp2> articlechp2s) throws Exception {

    //    XWPFDocument document = new XWPFDocument(); //creete a new documment 
    XWPFDocument doc = new XWPFDocument();

    //FileInputStream is = new FileInputStream("D:\\a.jpg"); 

    // doc.addPictureData(IOUtils.toByteArray(fs), doc.PICTURE_TYPE_JPEG);

    //doc.create(id,doc.getNextPicNameNumber(doc.PICTURE_TYPE_JPEG), 64, 64);
    XWPFParagraph para2 = doc.createParagraph();
    para2.setAlignment(ParagraphAlignment.CENTER);
    XWPFRun run = para2.createRun();
    run.setBold(true);/*ww w  .j a  v a2 s.  co  m*/
    run.setFontSize(40);

    // run.addPicture(pic, doc.PICTURE_TYPE_JPEG, "3", 0, 0);

    // run.addPicture(fs, doc.PICTURE_TYPE_JPEG, blipId, 100, 100);
    //  run.addPicture(is,2, "kamal", 20, 20);
    //run.addPicture(IOUtils.toByteArray(is), doc.PICTURE_TYPE_JPEG);
    run.setText("\n \t Descriptif technique  \n ");

    // pour article d projet
    XWPFParagraph para3 = doc.createParagraph();
    // para2.setAlignment(ParagraphAlignment.CENTER);
    run = para3.createRun();
    run.setText(" I- article de votre projet :");
    run.setFontSize(18);
    run.setBold(true);

    XWPFParagraph para4 = doc.createParagraph();// pour les article chp 1
    run = para4.createRun();
    run.setText("    I-1 article chapitre1   :   \n");
    run.setFontSize(14);
    run.setBold(true);
    run.addBreak();

    int i = 1;
    for (ArticleChp1 loadarticlechp1 : articlechp1s) {// kan3amar text1 dyal articlchp1
        run = para4.createRun();
        run.setText("      " + i + ")- " + loadarticlechp1.getTitre());
        run.addBreak();
        i++;
    }
    XWPFParagraph para5 = doc.createParagraph(); // pour les articles chp2
    run = para5.createRun();
    run.setText("    I-2 article chapitre2   :   \n");
    run.setFontSize(14);
    run.setBold(true);
    run.addBreak();
    i = 1;
    for (ArticleChp2 loadarticlechp2 : articlechp2s) {// text2 dyla articlechp2
        run = para5.createRun();
        run.setText("       " + i + ")- " + loadarticlechp2.getTitre());
        run.addBreak();
        i++;
    }

    // corpdetat de projet
    XWPFParagraph para6 = doc.createParagraph();
    // para2.setAlignment(ParagraphAlignment.CENTER);
    run = para6.createRun();
    run.setText("\t II- corps dtat :");
    run.setFontSize(18);
    run.setBold(true);
    run.addBreak();
    //  run.setColor("#999");

    i = 1;
    // bouclage pourles coprs et posts dyal kola corps 
    for (CorpDetat loaDetat : corpDetats) {
        run = para6.createRun();
        run.setText("       II-" + i + "- " + loaDetat.getTitre() + "  : ");
        run.setFontSize(16);

        run.addBreak();

        int j = 1;
        for (Post loadpost : loaDetat.getPosts()) {
            run = para6.createRun();
            run.setText("                 " + i + "-" + j + ")  " + loadpost.getTitre() + " ");
            run.addBreak();
            j++;
        }
        i++;
    }

    // 
    // bordeauraux
    XWPFParagraph para = doc.createParagraph();

    run = para.createRun();
    run.setBold(true);
    run.setFontSize(18);
    run.setText("     bordereau de prix ");
    run.addBreak();
    run = para.createRun();

    //Creates a table 
    XWPFTable tab = doc.createTable();
    tab.setWidth(500);

    tab.setCellMargins(50, 200, 50, 200);

    XWPFTableRow row1 = tab.getRow(0);

    row1.getCell(0).setText("designation");
    row1.getCell(0).setColor("FF9900");

    row1.addNewTableCell().setText("Unite");
    row1.getCell(1).setColor("FF9900");

    row1.addNewTableCell().setText("Quantite");
    row1.getCell(2).setColor("FF9900");

    row1.addNewTableCell().setText("prix");
    row1.getCell(3).setColor("FF9900");

    row1.addNewTableCell().setText("montant");
    row1.getCell(4).setColor("FF9900");
    i = 1;
    for (Bordereau loadbordereau : bordereaus) {

        XWPFTableRow loadRow = null;
        loadRow = tab.createRow();

        loadRow.getCell(0).setText(loadbordereau.getDesignation() + "");
        loadRow.getCell(1).setText(loadbordereau.getUnite());
        if (loadbordereau.getQuanite() == 0) {
            loadRow.getCell(2).setText("");

        } else {
            loadRow.getCell(2).setText(loadbordereau.getQuanite() + "");
        }
        if (loadbordereau.getPrix() == 0) {
        } else {
            loadRow.getCell(3).setText(loadbordereau.getPrix() + "");
        }
        if (loadbordereau.getMontant() == 0.0) {
        } else {
            loadRow.getCell(4).setText(loadbordereau.getMontant() + "");
        }

    }

    XWPFTableRow row3 = null;
    row3 = tab.createRow();
    row3.getCell(0).setText("TVA");
    row3.getCell(0).setColor("FF9900");

    XWPFTableRow row4 = null;
    row4 = tab.createRow();
    row4.getCell(0).setText("HTTC");
    row4.getCell(0).setColor("FF9900");

    try {
        doc.write(new FileOutputStream("D:\\test2.docx"));
        // InputStream pica = new FileInputStream("D:\\test2.docx");
        //FileInputStream fis = new FileInputStream("D:\\test2.docx");
        if (Desktop.isDesktopSupported()) {
            Desktop.getDesktop().open(new File("D:\\test2.docx"));
        }
    } catch (IOException ex) {

    }

}