Example usage for org.apache.poi.xssf.usermodel XSSFDrawing createTextbox

List of usage examples for org.apache.poi.xssf.usermodel XSSFDrawing createTextbox

Introduction

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

Prototype

public XSSFTextBox createTextbox(XSSFClientAnchor anchor) 

Source Link

Document

Constructs a textbox under the drawing.

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  w  w  w .  j av  a 2  s  .  com*/
        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.
 * //www  .ja v a2 s  .  c  om
 * @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);
}