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:org.cgiar.ccafs.marlo.utils.POISummary.java

License:Open Source License

public void textHead3Title(XWPFParagraph h2, String text) {
    h2.setAlignment(ParagraphAlignment.BOTH);
    XWPFRun h2Run = h2.createRun();
    this.addParagraphTextBreak(h2Run, text);
    h2Run.setColor(TITLE_FONT_COLOR);/*from w ww .j  a v a  2  s.c o  m*/
    h2Run.setBold(true);
    h2Run.setFontFamily(FONT_TYPE);
    h2Run.setFontSize(12);
}

From source file:org.cgiar.ccafs.marlo.utils.POISummary.java

License:Open Source License

public void textHeadCoverTitle(XWPFParagraph h1, String text) {
    h1.setAlignment(ParagraphAlignment.CENTER);
    XWPFRun h1Run = h1.createRun();
    this.addParagraphTextBreak(h1Run, text);
    h1Run.setColor(TEXT_FONT_COLOR);//w  w  w  .  j av  a 2 s .co  m
    h1Run.setBold(false);
    h1Run.setFontFamily(FONT_TYPE);
    h1Run.setFontSize(26);
}

From source file:org.cgiar.ccafs.marlo.utils.POISummary.java

License:Open Source License

public void textNotes(XWPFParagraph paragraph, String text) {
    paragraph.setAlignment(ParagraphAlignment.BOTH);
    XWPFRun paragraphRun = paragraph.createRun();
    this.addParagraphTextBreak(paragraphRun, text);
    paragraphRun.setColor(TEXT_FONT_COLOR);
    paragraphRun.setBold(false);//from   ww  w. ja  va2 s . co m
    paragraphRun.setFontFamily(FONT_TYPE);
    paragraphRun.setFontSize(10);
}

From source file:org.cgiar.ccafs.marlo.utils.POISummary.java

License:Open Source License

public void textParagraph(XWPFParagraph paragraph, String text) {
    paragraph.setAlignment(ParagraphAlignment.BOTH);
    XWPFRun paragraphRun = paragraph.createRun();
    this.addParagraphTextBreak(paragraphRun, text);
    paragraphRun.setColor(TEXT_FONT_COLOR);
    paragraphRun.setBold(false);//from   www . j  av  a  2s.c o m
    paragraphRun.setFontFamily(FONT_TYPE);
    paragraphRun.setFontSize(11);
}

From source file:org.cgiar.ccafs.marlo.utils.POISummary.java

License:Open Source License

public void textTable(XWPFDocument document, List<List<POIField>> sHeaders, List<List<POIField>> sData,
        Boolean highlightFirstColumn, String tableType) {
    XWPFTable table = document.createTable();
    int record = 0;
    int headerIndex = 0;
    for (List<POIField> poiParameters : sHeaders) {

        // Setting the Header
        XWPFTableRow tableRowHeader;/*from w ww . ja  v a2 s  .c om*/
        if (headerIndex == 0) {
            tableRowHeader = table.getRow(0);
        } else {
            tableRowHeader = table.createRow();
        }
        for (POIField poiParameter : poiParameters) {

            // Condition for table b cell color in fields 5 and 6
            if (tableType.equals("tableBAnnualReport") && (record == 4 || record == 5)) {
                TABLE_HEADER_FONT_COLOR = "DEEAF6";
            } else {
                TABLE_HEADER_FONT_COLOR = "FFF2CC";
            }

            if (headerIndex == 0) {
                if (record == 0) {
                    XWPFParagraph paragraph = tableRowHeader.getCell(0).addParagraph();
                    paragraph.setAlignment(poiParameter.getAlignment());
                    XWPFRun paragraphRun = paragraph.createRun();
                    this.addParagraphTextBreak(paragraphRun, poiParameter.getText());
                    paragraphRun.setColor(TEXT_FONT_COLOR);
                    if (poiParameter.getBold() != null) {
                        paragraphRun.setBold(poiParameter.getBold());
                    } else {
                        paragraphRun.setBold(true);
                    }
                    paragraphRun.setFontFamily(FONT_TYPE);
                    paragraphRun.setFontSize(TABLE_TEXT_FONT_SIZE);

                    tableRowHeader.getCell(record).setColor(TABLE_HEADER_FONT_COLOR);
                } else {
                    XWPFParagraph paragraph = tableRowHeader.createCell().addParagraph();
                    paragraph.setAlignment(poiParameter.getAlignment());
                    XWPFRun paragraphRun = paragraph.createRun();
                    this.addParagraphTextBreak(paragraphRun, poiParameter.getText());
                    paragraphRun.setColor(TEXT_FONT_COLOR);
                    if (poiParameter.getBold() != null) {
                        paragraphRun.setBold(poiParameter.getBold());
                    } else {
                        paragraphRun.setBold(true);
                    }
                    paragraphRun.setFontFamily(FONT_TYPE);
                    paragraphRun.setFontSize(TABLE_TEXT_FONT_SIZE);

                    tableRowHeader.getCell(record).setColor(TABLE_HEADER_FONT_COLOR);
                }
            } else {
                XWPFParagraph paragraph = tableRowHeader.getCell(record).addParagraph();
                paragraph.setAlignment(poiParameter.getAlignment());
                XWPFRun paragraphRun = paragraph.createRun();
                this.addParagraphTextBreak(paragraphRun, poiParameter.getText());
                paragraphRun.setColor(TEXT_FONT_COLOR);
                if (poiParameter.getBold() != null) {
                    paragraphRun.setBold(poiParameter.getBold());
                } else {
                    paragraphRun.setBold(true);
                }
                paragraphRun.setFontFamily(FONT_TYPE);
                paragraphRun.setFontSize(TABLE_TEXT_FONT_SIZE);

                tableRowHeader.getCell(record).setColor(TABLE_HEADER_FONT_COLOR);
            }
            record++;
        }
        headerIndex++;
        record = 0;
    }

    for (List<POIField> poiParameters : sData) {
        record = 0;

        // Condition for table b cell color in fields 5 and 6
        if (tableType.equals("tableBAnnualReport") && (record == 4 || record == 5)) {
            TABLE_HEADER_FONT_COLOR = "DEEAF6";
        } else {
            TABLE_HEADER_FONT_COLOR = "FFF2CC";
        }

        XWPFTableRow dataRow = table.createRow();
        for (POIField poiParameter : poiParameters) {
            count++;
            XWPFParagraph paragraph = dataRow.getCell(record).addParagraph();
            paragraph.setAlignment(poiParameter.getAlignment());
            // Hyperlink
            if (poiParameter.getUrl() != null && !poiParameter.getUrl().isEmpty()) {
                this.textHyperlink(poiParameter.getUrl(), poiParameter.getText(), paragraph);
            } else {
                XWPFRun paragraphRun = paragraph.createRun();
                this.addParagraphTextBreak(paragraphRun, poiParameter.getText());
                if (poiParameter.getFontColor() != null) {
                    paragraphRun.setColor(poiParameter.getFontColor());
                } else {
                    paragraphRun.setColor(TEXT_FONT_COLOR);
                }
                paragraphRun.setFontFamily(FONT_TYPE);
                paragraphRun.setFontSize(TABLE_TEXT_FONT_SIZE);

                // Condition for table b cell color in fields 5 and 6
                if (tableType.equals("tableBAnnualReport") && (record == 4 || record == 5)) {
                    TABLE_HEADER_FONT_COLOR = "DEEAF6";
                    dataRow.getCell(record).setColor("DEEAF6");
                } else {
                    TABLE_HEADER_FONT_COLOR = "FFF2CC";
                }

                // highlight and bold first and SecondColumn for table D1
                if (tableType.equals("tableD1AnnualReport") && (record == 0 || record == 1) && count < 9) {
                    dataRow.getCell(record).setColor("DEEAF6");
                    paragraphRun.setBold(true);
                } else if (tableType.equals("tableD1AnnualReport") && count >= 9
                        && (record == 0 || record == 1)) {
                    dataRow.getCell(record).setColor("E2EFD9");
                    paragraphRun.setBold(true);

                } else {
                    if (highlightFirstColumn && record == 0) {
                        dataRow.getCell(record).setColor(TABLE_HEADER_FONT_COLOR);
                        if (poiParameter.getBold() != null) {
                            paragraphRun.setBold(poiParameter.getBold());
                        } else {
                            paragraphRun.setBold(true);
                        }
                    } else {
                        if (poiParameter.getBold() != null) {
                            paragraphRun.setBold(poiParameter.getBold());
                        } else {
                            paragraphRun.setBold(false);
                        }
                    }
                }

            }
            record++;
        }

    }

    switch (tableType) {
    case "tableA":
        this.tableAStyle(table);
        break;
    case "tableE":
        this.tableEStyle(table);
        break;
    case "tableC":
        this.tableCStyle(table);
        break;
    case "tableF":
        this.tableFStyle(table);
        break;
    case "tableG":
        this.tableGStyle(table);
        break;

    case "tableAAnnualReport":
        this.tableBAnnualReportStyle(table);
        break;
    case "tableA1AnnualReport":
        this.tableA1AnnualReportStyle(table);
        break;
    case "tableA2AnnualReport":
        this.tableA1AnnualReportStyle(table);
        break;
    case "tableBAnnualReport":
        this.tableBAnnualReportStyle(table);
        break;
    case "tableCAnnualReport":
        count = 0;
        this.tableCStyle(table);
        break;
    case "tableD1AnnualReport":
        this.tableD1AnnualReportStyle(table);
        break;
    case "tableD2AnnualReport":
        count = 0;
        this.tableAStyle(table);
        break;
    case "tableEAnnualReport":
        this.tableGStyle(table);
        break;
    case "tableFAnnualReport":
        this.tableFStyle(table);
        break;
    case "tableGAnnualReport":
        this.tableGStyle(table);
        break;
    case "tableHAnnualReport":
        this.tableGStyle(table);
        break;
    case "tableIAnnualReport":
        this.tableIAnnualReportStyle(table);
        break;
    case "tableJAnnualReport":
        this.tableJAnnualReportStyle(table);
        break;
    }
    if (tableType.contains("AnnualReport")) {
        table.getCTTbl().addNewTblPr().addNewTblW().setW(BigInteger.valueOf(13350));
    } else {
        table.getCTTbl().addNewTblPr().addNewTblW().setW(BigInteger.valueOf(12000));
    }

}

From source file:org.eclipse.sw360.licenseinfo.outputGenerators.DocxGenerator.java

License:Open Source License

private void addCopyrights(XWPFDocument document, LicenseInfoParsingResult parsingResult) {
    XWPFRun copyrightTitleRun = document.createParagraph().createRun();
    addFormattedText(copyrightTitleRun, "Copyrights", FONT_SIZE, true);
    for (String copyright : getReleaseCopyrights(parsingResult)) {
        XWPFParagraph copyPara = document.createParagraph();
        copyPara.setSpacingAfter(0);/*w  w w. j  ava2  s. com*/
        setText(copyPara.createRun(), copyright);
    }
}

From source file:org.eclipse.sw360.licenseinfo.outputGenerators.DocxGenerator.java

License:Open Source License

private void addLicenseObligations(XWPFDocument document, String spdxLicense) throws TException {
    List<License> sw360Licenses = getLicenses();
    XWPFRun todoTitleRun = document.createParagraph().createRun();
    addNewLines(todoTitleRun, 0);//from  ww  w  .j  av a 2  s  .  c  o  m
    Set<String> todos = getTodosFromLicenses(spdxLicense, sw360Licenses);
    addFormattedText(todoTitleRun, "Obligations for license " + spdxLicense + ":", FONT_SIZE, true);
    for (String todo : todos) {
        XWPFParagraph copyPara = document.createParagraph();
        copyPara.setSpacingAfter(0);
        XWPFRun todoRun = copyPara.createRun();
        setText(todoRun, todo);
        addNewLines(todoRun, 1);
    }
}

From source file:org.eclipse.sw360.licenseinfo.outputGenerators.DocxUtils.java

License:Open Source License

public static void addNewLines(XWPFDocument document, int numberOfNewlines) {
    XWPFParagraph paragraph = document.createParagraph();
    XWPFRun run = paragraph.createRun();
    addNewLines(run, numberOfNewlines);//  w w  w  .j a  v a  2s.  c o  m
}

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);/*  ww  w  .  j ava2s  .c  om*/
}

From source file:org.eclipse.sw360.licenseinfo.outputGenerators.DocxUtils.java

License:Open Source License

public static void addBulletList(XWPFDocument document, List<String> bulletListItems,
        boolean bulletListItemsAsLink) throws XmlException {
    CTNumbering cTNumbering = CTNumbering.Factory.parse(cTAbstractNumBulletXML);
    CTAbstractNum cTAbstractNum = cTNumbering.getAbstractNumArray(0);
    XWPFAbstractNum abstractNum = new XWPFAbstractNum(cTAbstractNum);
    XWPFNumbering numbering = document.createNumbering();
    BigInteger abstractNumID = numbering.addAbstractNum(abstractNum);
    BigInteger numID = numbering.addNum(abstractNumID);

    for (int i = 0; i < bulletListItems.size(); i++) {
        String bulletItem = bulletListItems.get(i);
        XWPFParagraph paragraph = document.createParagraph();
        paragraph.setNumID(numID);//from   w ww .  j  a  v  a2  s.  c o  m
        if (bulletListItemsAsLink) {
            addBookmarkHyperLink(paragraph, bulletItem, bulletItem);
        } else {
            setText(paragraph.createRun(), bulletItem);
        }
        if (i < bulletListItems.size() - 1) {
            paragraph.setSpacingAfter(0);
        }
    }
}