Example usage for org.apache.poi.xssf.usermodel XSSFTextBox setText

List of usage examples for org.apache.poi.xssf.usermodel XSSFTextBox setText

Introduction

In this page you can find the example usage for org.apache.poi.xssf.usermodel XSSFTextBox setText.

Prototype

public void setText(String text) 

Source Link

Document

Set a single paragraph of text on the shape.

Usage

From source file:net.mcnewfamily.rmcnew.writer.AbstractXlsxWriter.java

License:Open Source License

protected void createTextBox(XSSFSheet xssfSheet, XSSFClientAnchor xssfClientAnchor, String text) {
    if (xssfSheet != null) {
        XSSFDrawing xssfDrawing = xssfSheet.createDrawingPatriarch();
        XSSFTextBox xssfTextBox = xssfDrawing.createTextbox(xssfClientAnchor);
        xssfTextBox.setText(new XSSFRichTextString(text));

    } else {//from ww  w.j  a  v  a 2  s  .  c o  m
        throw new IllegalArgumentException("Cannot create drawing on  null or empty sheet!");
    }
}

From source file:org.cgiar.ccafs.ap.summaries.projects.xlsx.BaseXLS.java

License:Open Source License

/**
 * This method writes the title box into the given sheet.
 * // w w  w.  j  av  a2 s .c o m
 * @param sheet is the sheet where you want to write the title box.
 * @param text is the title of the report.
 */
public void writeTitleBox(Sheet sheet, String text) {

    XSSFDrawing draw = (XSSFDrawing) sheet.createDrawingPatriarch();
    XSSFClientAnchor anchor = new XSSFClientAnchor(0, 0, 1, 1, 1, 1, 3, 6);
    anchor.setAnchorType(2);
    XSSFTextBox textbox = draw.createTextbox(anchor);

    textbox.setFillColor(TEXTBOX_BACKGROUND_COLOR_RGB.getRed(), TEXTBOX_BACKGROUND_COLOR_RGB.getGreen(),
            TEXTBOX_BACKGROUND_COLOR_RGB.getBlue());
    textbox.setVerticalAlignment(VerticalAlignment.CENTER);

    XSSFRichTextString stringX = new XSSFRichTextString();
    Font font = workbook.createFont();
    font.setFontHeightInPoints((short) 20);
    font.setFontName("Tahoma");
    font.setColor(TEXTBOX_FONT_COLOR_INDEX);
    stringX.append(text);

    stringX.applyFont(font);
    textbox.setText(stringX);
}