Example usage for org.apache.poi.ss.usermodel CellStyle setAlignment

List of usage examples for org.apache.poi.ss.usermodel CellStyle setAlignment

Introduction

In this page you can find the example usage for org.apache.poi.ss.usermodel CellStyle setAlignment.

Prototype

void setAlignment(HorizontalAlignment align);

Source Link

Document

set the type of horizontal alignment for the cell

Usage

From source file:it.eng.spagobi.engines.console.exporter.types.ExporterExcel.java

License:Mozilla Public License

public CellStyle buildHeaderCellStyle(Sheet sheet) {
    CellStyle cellStyle = sheet.getWorkbook().createCellStyle();
    cellStyle.setAlignment(CellStyle.ALIGN_LEFT);
    cellStyle.setVerticalAlignment(CellStyle.ALIGN_CENTER);
    cellStyle.setFillForegroundColor(IndexedColors.WHITE.getIndex());
    cellStyle.setFillPattern(CellStyle.SOLID_FOREGROUND);
    /*        cellStyle.setBorderBottom(CellStyle.BORDER_THIN);
            cellStyle.setBorderLeft(CellStyle.BORDER_THIN);
            cellStyle.setBorderRight(CellStyle.BORDER_THIN);
            cellStyle.setBorderTop(CellStyle.BORDER_THIN);*/

    Font font = sheet.getWorkbook().createFont();
    font.setFontHeightInPoints((short) 12);
    font.setFontName("Arial");
    font.setColor(IndexedColors.BLACK.getIndex());
    font.setBoldweight(Font.BOLDWEIGHT_BOLD);
    cellStyle.setFont(font);//from   www.  j  av  a  2  s . c  om
    return cellStyle;
}

From source file:it.eng.spagobi.engines.console.exporter.types.ExporterExcel.java

License:Mozilla Public License

public CellStyle buildDataCellStyle(Sheet sheet) {
    CellStyle cellStyle = sheet.getWorkbook().createCellStyle();
    cellStyle.setAlignment(CellStyle.ALIGN_LEFT);
    cellStyle.setVerticalAlignment(CellStyle.ALIGN_CENTER);
    cellStyle.setFillForegroundColor(IndexedColors.WHITE.getIndex());
    cellStyle.setFillPattern(CellStyle.SOLID_FOREGROUND);
    /*        cellStyle.setBorderBottom(CellStyle.BORDER_THIN);
            cellStyle.setBorderLeft(CellStyle.BORDER_THIN);
            cellStyle.setBorderRight(CellStyle.BORDER_THIN);
            cellStyle.setBorderTop(CellStyle.BORDER_THIN);*/
    cellStyle.setWrapText(false);/*from   ww  w. j a v a2s . co  m*/
    Font font = sheet.getWorkbook().createFont();
    font.setFontHeightInPoints((short) 10);
    font.setFontName("Arial");
    font.setColor(IndexedColors.BLACK.getIndex());
    cellStyle.setFont(font);
    return cellStyle;
}

From source file:it.eng.spagobi.engines.qbe.crosstable.exporter.CrosstabXLSExporter.java

License:Mozilla Public License

public CellStyle buildNACellStyle(Sheet sheet) {
    CellStyle cellStyleForNA = this.buildDataCellStyle(sheet);
    cellStyleForNA.setAlignment(CellStyle.ALIGN_CENTER);
    return cellStyleForNA;
}

From source file:it.eng.spagobi.engines.qbe.crosstable.exporter.CrosstabXLSExporter.java

License:Mozilla Public License

public CellStyle buildDimensionCellStyle(Sheet sheet) {
    CellStyle cellStyle = sheet.getWorkbook().createCellStyle();
    cellStyle.setAlignment(CellStyle.ALIGN_CENTER);
    cellStyle.setVerticalAlignment(CellStyle.ALIGN_CENTER);

    String headerBGColor = (String) this.getProperty(PROPERTY_DIMENSION_NAME_BACKGROUND_COLOR);
    logger.debug("Header background color : " + headerBGColor);
    short backgroundColorIndex = headerBGColor != null ? IndexedColors.valueOf(headerBGColor).getIndex()
            : IndexedColors.valueOf(DEFAULT_DIMENSION_NAME_BACKGROUND_COLOR).getIndex();
    cellStyle.setFillForegroundColor(backgroundColorIndex);

    cellStyle.setFillPattern(CellStyle.SOLID_FOREGROUND);

    cellStyle.setBorderBottom(CellStyle.BORDER_THIN);
    cellStyle.setBorderLeft(CellStyle.BORDER_THIN);
    cellStyle.setBorderRight(CellStyle.BORDER_THIN);
    cellStyle.setBorderTop(CellStyle.BORDER_THIN);

    String bordeBorderColor = (String) this.getProperty(PROPERTY_HEADER_BORDER_COLOR);
    logger.debug("Header border color : " + bordeBorderColor);
    short borderColorIndex = bordeBorderColor != null ? IndexedColors.valueOf(bordeBorderColor).getIndex()
            : IndexedColors.valueOf(DEFAULT_HEADER_BORDER_COLOR).getIndex();

    cellStyle.setLeftBorderColor(borderColorIndex);
    cellStyle.setRightBorderColor(borderColorIndex);
    cellStyle.setBottomBorderColor(borderColorIndex);
    cellStyle.setTopBorderColor(borderColorIndex);

    Font font = sheet.getWorkbook().createFont();

    Short headerFontSize = (Short) this.getProperty(PROPERTY_HEADER_FONT_SIZE);
    logger.debug("Header font size : " + headerFontSize);
    short headerFontSizeShort = headerFontSize != null ? headerFontSize.shortValue() : DEFAULT_HEADER_FONT_SIZE;
    font.setFontHeightInPoints(headerFontSizeShort);

    String fontName = (String) this.getProperty(PROPERTY_FONT_NAME);
    logger.debug("Font name : " + fontName);
    fontName = fontName != null ? fontName : DEFAULT_FONT_NAME;
    font.setFontName(fontName);//ww w.  ja  va2  s . com

    String color = (String) this.getProperty(PROPERTY_DIMENSION_NAME_COLOR);
    logger.debug("Dimension color : " + color);
    short colorIndex = bordeBorderColor != null ? IndexedColors.valueOf(color).getIndex()
            : IndexedColors.valueOf(DEFAULT_DIMENSION_NAME_COLOR).getIndex();
    font.setColor(colorIndex);

    font.setBoldweight(Font.BOLDWEIGHT_BOLD);
    font.setItalic(true);
    cellStyle.setFont(font);
    return cellStyle;
}

From source file:it.eng.spagobi.engines.qbe.crosstable.exporter.CrosstabXLSExporter.java

License:Mozilla Public License

public CellStyle buildHeaderCellStyle(Sheet sheet) {
    CellStyle cellStyle = sheet.getWorkbook().createCellStyle();
    cellStyle.setAlignment(CellStyle.ALIGN_LEFT);
    cellStyle.setVerticalAlignment(CellStyle.ALIGN_CENTER);

    String headerBGColor = (String) this.getProperty(PROPERTY_HEADER_BACKGROUND_COLOR);
    logger.debug("Header background color : " + headerBGColor);
    short backgroundColorIndex = headerBGColor != null ? IndexedColors.valueOf(headerBGColor).getIndex()
            : IndexedColors.valueOf(DEFAULT_HEADER_BACKGROUND_COLOR).getIndex();
    cellStyle.setFillForegroundColor(backgroundColorIndex);

    cellStyle.setFillPattern(CellStyle.SOLID_FOREGROUND);

    cellStyle.setBorderBottom(CellStyle.BORDER_THIN);
    cellStyle.setBorderLeft(CellStyle.BORDER_THIN);
    cellStyle.setBorderRight(CellStyle.BORDER_THIN);
    cellStyle.setBorderTop(CellStyle.BORDER_THIN);

    String bordeBorderColor = (String) this.getProperty(PROPERTY_HEADER_BORDER_COLOR);
    logger.debug("Header border color : " + bordeBorderColor);
    short borderColorIndex = bordeBorderColor != null ? IndexedColors.valueOf(bordeBorderColor).getIndex()
            : IndexedColors.valueOf(DEFAULT_HEADER_BORDER_COLOR).getIndex();

    cellStyle.setLeftBorderColor(borderColorIndex);
    cellStyle.setRightBorderColor(borderColorIndex);
    cellStyle.setBottomBorderColor(borderColorIndex);
    cellStyle.setTopBorderColor(borderColorIndex);

    Font font = sheet.getWorkbook().createFont();

    Short headerFontSize = (Short) this.getProperty(PROPERTY_HEADER_FONT_SIZE);
    logger.debug("Header font size : " + headerFontSize);
    short headerFontSizeShort = headerFontSize != null ? headerFontSize.shortValue() : DEFAULT_HEADER_FONT_SIZE;
    font.setFontHeightInPoints(headerFontSizeShort);

    String fontName = (String) this.getProperty(PROPERTY_FONT_NAME);
    logger.debug("Font name : " + fontName);
    fontName = fontName != null ? fontName : DEFAULT_FONT_NAME;
    font.setFontName(fontName);//from w w w. ja v a 2s  .  com

    String headerColor = (String) this.getProperty(PROPERTY_HEADER_COLOR);
    logger.debug("Header color : " + headerColor);
    short headerColorIndex = bordeBorderColor != null ? IndexedColors.valueOf(headerColor).getIndex()
            : IndexedColors.valueOf(DEFAULT_HEADER_COLOR).getIndex();
    font.setColor(headerColorIndex);

    font.setBoldweight(Font.BOLDWEIGHT_BOLD);
    cellStyle.setFont(font);
    return cellStyle;
}

From source file:it.eng.spagobi.engines.qbe.crosstable.exporter.CrosstabXLSExporter.java

License:Mozilla Public License

public CellStyle buildDataCellStyle(Sheet sheet) {
    CellStyle cellStyle = sheet.getWorkbook().createCellStyle();
    cellStyle.setAlignment(CellStyle.ALIGN_RIGHT);
    cellStyle.setVerticalAlignment(CellStyle.ALIGN_CENTER);

    String cellBGColor = (String) this.getProperty(PROPERTY_CELL_BACKGROUND_COLOR);
    logger.debug("Cell background color : " + cellBGColor);
    short backgroundColorIndex = cellBGColor != null ? IndexedColors.valueOf(cellBGColor).getIndex()
            : IndexedColors.valueOf(DEFAULT_CELL_BACKGROUND_COLOR).getIndex();
    cellStyle.setFillForegroundColor(backgroundColorIndex);

    cellStyle.setFillPattern(CellStyle.SOLID_FOREGROUND);

    cellStyle.setBorderBottom(CellStyle.BORDER_THIN);
    cellStyle.setBorderLeft(CellStyle.BORDER_THIN);
    cellStyle.setBorderRight(CellStyle.BORDER_THIN);
    cellStyle.setBorderTop(CellStyle.BORDER_THIN);

    String bordeBorderColor = (String) this.getProperty(PROPERTY_CELL_BORDER_COLOR);
    logger.debug("Cell border color : " + bordeBorderColor);
    short borderColorIndex = bordeBorderColor != null ? IndexedColors.valueOf(bordeBorderColor).getIndex()
            : IndexedColors.valueOf(DEFAULT_CELL_BORDER_COLOR).getIndex();

    cellStyle.setLeftBorderColor(borderColorIndex);
    cellStyle.setRightBorderColor(borderColorIndex);
    cellStyle.setBottomBorderColor(borderColorIndex);
    cellStyle.setTopBorderColor(borderColorIndex);

    Font font = sheet.getWorkbook().createFont();

    Short cellFontSize = (Short) this.getProperty(PROPERTY_CELL_FONT_SIZE);
    logger.debug("Cell font size : " + cellFontSize);
    short cellFontSizeShort = cellFontSize != null ? cellFontSize.shortValue() : DEFAULT_CELL_FONT_SIZE;
    font.setFontHeightInPoints(cellFontSizeShort);

    String fontName = (String) this.getProperty(PROPERTY_FONT_NAME);
    logger.debug("Font name : " + fontName);
    fontName = fontName != null ? fontName : DEFAULT_FONT_NAME;
    font.setFontName(fontName);//  w  w  w  .  j  a va  2s .c  om

    String cellColor = (String) this.getProperty(PROPERTY_CELL_COLOR);
    logger.debug("Cell color : " + cellColor);
    short cellColorIndex = cellColor != null ? IndexedColors.valueOf(cellColor).getIndex()
            : IndexedColors.valueOf(DEFAULT_CELL_COLOR).getIndex();
    font.setColor(cellColorIndex);

    cellStyle.setFont(font);
    return cellStyle;
}

From source file:it.eng.spagobi.engines.qbe.exporter.QbeXLSExporter.java

License:Mozilla Public License

public CellStyle buildHeaderCellStyle(Sheet sheet) {

    CellStyle cellStyle = sheet.getWorkbook().createCellStyle();
    cellStyle.setAlignment(CellStyle.ALIGN_LEFT);
    cellStyle.setVerticalAlignment(CellStyle.ALIGN_CENTER);

    String headerBGColor = (String) this.getProperty(PROPERTY_HEADER_BACKGROUND_COLOR);
    logger.debug("Header background color : " + headerBGColor);
    short backgroundColorIndex = headerBGColor != null ? IndexedColors.valueOf(headerBGColor).getIndex()
            : IndexedColors.valueOf(DEFAULT_HEADER_BACKGROUND_COLOR).getIndex();
    cellStyle.setFillForegroundColor(backgroundColorIndex);

    cellStyle.setFillPattern(CellStyle.SOLID_FOREGROUND);

    cellStyle.setBorderBottom(CellStyle.BORDER_THIN);
    cellStyle.setBorderLeft(CellStyle.BORDER_THIN);
    cellStyle.setBorderRight(CellStyle.BORDER_THIN);
    cellStyle.setBorderTop(CellStyle.BORDER_THIN);

    String bordeBorderColor = (String) this.getProperty(PROPERTY_HEADER_BORDER_COLOR);
    logger.debug("Header border color : " + bordeBorderColor);
    short borderColorIndex = bordeBorderColor != null ? IndexedColors.valueOf(bordeBorderColor).getIndex()
            : IndexedColors.valueOf(DEFAULT_HEADER_BORDER_COLOR).getIndex();

    cellStyle.setLeftBorderColor(borderColorIndex);
    cellStyle.setRightBorderColor(borderColorIndex);
    cellStyle.setBottomBorderColor(borderColorIndex);
    cellStyle.setTopBorderColor(borderColorIndex);

    Font font = sheet.getWorkbook().createFont();

    Short headerFontSize = (Short) this.getProperty(PROPERTY_HEADER_FONT_SIZE);
    logger.debug("Header font size : " + headerFontSize);
    short headerFontSizeShort = headerFontSize != null ? headerFontSize.shortValue() : DEFAULT_HEADER_FONT_SIZE;
    font.setFontHeightInPoints(headerFontSizeShort);

    String fontName = (String) this.getProperty(PROPERTY_FONT_NAME);
    logger.debug("Font name : " + fontName);
    fontName = fontName != null ? fontName : DEFAULT_FONT_NAME;
    font.setFontName(fontName);/*from  w  ww  .ja  v  a2 s .c  o m*/

    String headerColor = (String) this.getProperty(PROPERTY_HEADER_COLOR);
    logger.debug("Header color : " + headerColor);
    short headerColorIndex = bordeBorderColor != null ? IndexedColors.valueOf(headerColor).getIndex()
            : IndexedColors.valueOf(DEFAULT_HEADER_COLOR).getIndex();
    font.setColor(headerColorIndex);

    font.setBoldweight(Font.BOLDWEIGHT_BOLD);
    cellStyle.setFont(font);
    return cellStyle;
}

From source file:it.eng.spagobi.engines.qbe.exporter.QbeXLSExporter.java

License:Mozilla Public License

public CellStyle buildCellStyle(Sheet sheet) {

    CellStyle cellStyle = sheet.getWorkbook().createCellStyle();
    cellStyle.setAlignment(CellStyle.ALIGN_RIGHT);
    cellStyle.setVerticalAlignment(CellStyle.ALIGN_CENTER);

    String cellBGColor = (String) this.getProperty(PROPERTY_CELL_BACKGROUND_COLOR);
    logger.debug("Cell background color : " + cellBGColor);
    short backgroundColorIndex = cellBGColor != null ? IndexedColors.valueOf(cellBGColor).getIndex()
            : IndexedColors.valueOf(DEFAULT_CELL_BACKGROUND_COLOR).getIndex();
    cellStyle.setFillForegroundColor(backgroundColorIndex);

    cellStyle.setFillPattern(CellStyle.SOLID_FOREGROUND);

    cellStyle.setBorderBottom(CellStyle.BORDER_THIN);
    cellStyle.setBorderLeft(CellStyle.BORDER_THIN);
    cellStyle.setBorderRight(CellStyle.BORDER_THIN);
    cellStyle.setBorderTop(CellStyle.BORDER_THIN);

    String bordeBorderColor = (String) this.getProperty(PROPERTY_CELL_BORDER_COLOR);
    logger.debug("Cell border color : " + bordeBorderColor);
    short borderColorIndex = bordeBorderColor != null ? IndexedColors.valueOf(bordeBorderColor).getIndex()
            : IndexedColors.valueOf(DEFAULT_CELL_BORDER_COLOR).getIndex();

    cellStyle.setLeftBorderColor(borderColorIndex);
    cellStyle.setRightBorderColor(borderColorIndex);
    cellStyle.setBottomBorderColor(borderColorIndex);
    cellStyle.setTopBorderColor(borderColorIndex);

    Font font = sheet.getWorkbook().createFont();

    Short cellFontSize = (Short) this.getProperty(PROPERTY_CELL_FONT_SIZE);
    logger.debug("Cell font size : " + cellFontSize);
    short cellFontSizeShort = cellFontSize != null ? cellFontSize.shortValue() : DEFAULT_CELL_FONT_SIZE;
    font.setFontHeightInPoints(cellFontSizeShort);

    String fontName = (String) this.getProperty(PROPERTY_FONT_NAME);
    logger.debug("Font name : " + fontName);
    fontName = fontName != null ? fontName : DEFAULT_FONT_NAME;
    font.setFontName(fontName);/*from   ww w. j  ava  2 s . c om*/

    String cellColor = (String) this.getProperty(PROPERTY_CELL_COLOR);
    logger.debug("Cell color : " + cellColor);
    short cellColorIndex = cellColor != null ? IndexedColors.valueOf(cellColor).getIndex()
            : IndexedColors.valueOf(DEFAULT_CELL_COLOR).getIndex();
    font.setColor(cellColorIndex);

    cellStyle.setFont(font);
    return cellStyle;
}

From source file:it.eng.spagobi.engines.worksheet.exporter.WorkSheetXLSExporter.java

License:Mozilla Public License

public CellStyle buildHeaderTitleCellStyle(Sheet sheet) {
    CellStyle cellStyle = sheet.getWorkbook().createCellStyle();
    cellStyle.setAlignment(CellStyle.ALIGN_LEFT);
    cellStyle.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
    Font font = sheet.getWorkbook().createFont();
    font.setFontHeightInPoints(HEADER_FONT_SIZE);
    font.setFontName(FONT_NAME);//www  .ja  v  a  2  s .  c  om
    font.setColor(IndexedColors.DARK_BLUE.getIndex());
    font.setBoldweight(Font.BOLDWEIGHT_BOLD);
    cellStyle.setFont(font);
    return cellStyle;
}

From source file:it.eng.spagobi.engines.worksheet.exporter.WorkSheetXLSExporter.java

License:Mozilla Public License

public CellStyle buildMetadataTitleCellStyle(Sheet sheet) {
    CellStyle cellStyle = sheet.getWorkbook().createCellStyle();
    cellStyle.setAlignment(CellStyle.ALIGN_LEFT);
    cellStyle.setVerticalAlignment(CellStyle.VERTICAL_TOP);
    cellStyle.setWrapText(true);/* w w  w  .j a va 2  s  . com*/
    Font font = sheet.getWorkbook().createFont();
    font.setBoldweight(Font.BOLDWEIGHT_BOLD);
    font.setFontHeightInPoints(METADATA_TITLE_FONT_SIZE);
    font.setFontName(FONT_NAME);
    cellStyle.setFont(font);
    return cellStyle;
}