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

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

Introduction

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

Prototype

public void setVerticalAlignment(VerticalAlignment anchor) 

Source Link

Document

Sets the type of vertical alignment for the text within the shape.

Usage

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.
 * //from w  w w. j a  v  a 2  s  .  co  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);
}