Example usage for org.apache.poi.xwpf.usermodel XWPFRun setBold

List of usage examples for org.apache.poi.xwpf.usermodel XWPFRun setBold

Introduction

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

Prototype

@Override
public void setBold(boolean value) 

Source Link

Document

Whether the bold property shall be applied to all non-complex script characters in the contents of this run when displayed in a document.

Usage

From source file:org.articleEditor.insertContent.DocumentUpdater1.java

License:Apache License

public void applyAttributes(XWPFRun run, AttributeSet attributes) {
    Enumeration attributeNames = attributes.getAttributeNames();
    while (attributeNames.hasMoreElements()) {
        Object attributeName = attributeNames.nextElement();
        Object attributeValue = attributes.getAttribute(attributeName);
        if (attributeName == Bold) {
            run.setBold((Boolean) attributeValue);
        } else if (attributeName == Italic) {
            run.setItalic((Boolean) attributeValue);
        } else if (attributeName == Underline) {
            run.setUnderline((Boolean) attributeValue ? UnderlinePatterns.SINGLE : UnderlinePatterns.NONE);
        } else if (attributeName == FontFamily || attributeName == Family) {
            run.setFontFamily((String) attributeValue);
        } else if (attributeName == FontSize) {
            run.setFontSize(((Number) attributeValue).intValue());
        } else if (attributeName == Foreground) {
            Color color = (Color) attributeValue;
            String rgb = Integer.toHexString((color.getRGB() & 0xffffff) | 0x1000000).substring(1);
            run.setColor(rgb);/*from  w  w  w .j ava 2 s.c  om*/
        } else if (attributeName == Background) {
            Color color = (Color) attributeValue;
            String rgb = Integer.toHexString((color.getRGB() & 0xffffff) | 0x1000000).substring(1);
            //run.getCTR().getRPr().setHighlight();
        } else if (attributeName == Subscript) {
            run.setSubscript((Boolean) attributeValue ? VerticalAlign.SUBSCRIPT : VerticalAlign.BASELINE);
        } else if (attributeName == Superscript) {
            run.setSubscript((Boolean) attributeValue ? VerticalAlign.SUPERSCRIPT : VerticalAlign.BASELINE);
        } else if (attributeName == StrikeThrough) {
            run.setStrike((Boolean) attributeValue);
        } else if (attributeName == Alignment) {
            ParagraphAlignment alignment = documentToPOI((Integer) attributeValue);
            run.getParagraph().setAlignment(alignment);
        }
    }
}

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

License:Open Source License

/**
 * Head 1 Title/*from  w ww.j a  v a 2s  . co m*/
 * 
 * @param h1
 * @param text
 */
public void textHead1Title(XWPFParagraph h1, String text) {
    h1.setAlignment(ParagraphAlignment.BOTH);
    XWPFRun h1Run = h1.createRun();
    this.addParagraphTextBreak(h1Run, text);
    h1Run.setColor(TITLE_FONT_COLOR);
    h1Run.setBold(true);
    h1Run.setFontFamily(FONT_TYPE);
    h1Run.setFontSize(16);
}

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

License:Open Source License

public void textHead2Title(XWPFParagraph h2, String text) {
    h2.setAlignment(ParagraphAlignment.BOTH);
    XWPFRun h2Run = h2.createRun();
    this.addParagraphTextBreak(h2Run, text);
    h2Run.setColor(TITLE_FONT_COLOR);//w  w w  . j  a v a 2 s  . com
    h2Run.setBold(true);
    h2Run.setFontFamily(FONT_TYPE);
    h2Run.setFontSize(14);
}

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);// 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);//from  w w  w .java  2  s.c o  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);
    paragraphRun.setFontFamily(FONT_TYPE);
    paragraphRun.setFontSize(10);//from   w ww.  j  av  a 2  s.  c  om
}

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);
    paragraphRun.setFontFamily(FONT_TYPE);
    paragraphRun.setFontSize(11);/*from  ww  w  . j a v  a2 s. c  om*/
}

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;/*w w w  . j  av  a  2s.  c o  m*/
        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.DocxUtils.java

License:Open Source License

public static void addFormattedText(XWPFRun run, String text, String fontFamily, int fontSize, boolean bold,
        String rrggbbColor) {/*from ww  w  .  jav  a2 s  .  c  om*/
    run.setFontSize(fontSize);
    run.setFontFamily(fontFamily);
    run.setBold(bold);
    if (rrggbbColor != null) {
        run.setColor(rrggbbColor);
    }
    setText(run, text);
}

From source file:org.obeonetwork.m2doc.generator.BookmarkManager.java

License:Open Source License

/**
 * Inserts a reference to the given {@link CTBookmark} with the given text in the given {@link XWPFParagraph}.
 * /*from  w ww  . j a  va  2 s.c  o m*/
 * @param paragraph
 *            the {@link XWPFParagraph}
 * @param name
 *            the bookmark name
 * @param text
 *            the text
 * @return the {@link CTText} corresponding to the reference.
 */
private CTText insertPendingReference(XWPFParagraph paragraph, String name, String text) {
    final byte[] id = getReferenceID(name);
    final XWPFRun beginRun = paragraph.createRun();
    beginRun.getCTR().setRsidR(id);
    beginRun.getCTR().addNewFldChar().setFldCharType(STFldCharType.BEGIN);

    final XWPFRun preservedRun = paragraph.createRun();
    preservedRun.getCTR().setRsidR(id);
    final CTText pgcttext = preservedRun.getCTR().addNewInstrText();
    pgcttext.setSpace(Space.PRESERVE);

    final XWPFRun separateRun = paragraph.createRun();
    separateRun.getCTR().setRsidR(id);
    separateRun.getCTR().addNewFldChar().setFldCharType(STFldCharType.SEPARATE);

    final XWPFRun textRun = paragraph.createRun();
    textRun.getCTR().setRsidR(id);
    textRun.getCTR().addNewRPr().addNewNoProof();
    textRun.setText(text);
    textRun.setBold(true);

    final XWPFRun endRun = paragraph.createRun();
    endRun.getCTR().setRsidR(id);
    endRun.getCTR().addNewFldChar().setFldCharType(STFldCharType.END);

    return pgcttext;
}