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

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

Introduction

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

Prototype

void setVerticalAlignment(VerticalAlignment align);

Source Link

Document

set the type of vertical alignment for the cell

Usage

From source file:com.catexpress.util.FormatosPOI.java

public CellStyle estiloTotales(Workbook wb) {
    CellStyle estiloCelda = wb.createCellStyle();
    Font fuente = wb.createFont();
    estiloCelda.setFillForegroundColor(IndexedColors.ROYAL_BLUE.getIndex());
    estiloCelda.setFillPattern(CellStyle.SOLID_FOREGROUND);
    fuente.setFontName("Calibri");
    fuente.setBold(true);/*from  w  w w  . j a va2s  . co m*/
    fuente.setFontHeightInPoints((short) 14);
    fuente.setColor(IndexedColors.WHITE.getIndex());
    estiloCelda.setFont(fuente);
    estiloCelda.setVerticalAlignment(VerticalAlignment.CENTER);
    estiloCelda.setAlignment(HorizontalAlignment.CENTER);
    estiloCelda.setBorderBottom(BorderStyle.MEDIUM);
    estiloCelda.setBorderTop(BorderStyle.MEDIUM);
    estiloCelda.setBorderLeft(BorderStyle.MEDIUM);
    estiloCelda.setBorderRight(BorderStyle.MEDIUM);

    return estiloCelda;
}

From source file:com.catexpress.util.FormatosPOI.java

public CellStyle estiloCuadro(Workbook wb, int tipo) {
    CellStyle estiloCelda = wb.createCellStyle();
    Font fuente = wb.createFont();
    if (tipo == AMARILLO) {
        estiloCelda.setFillForegroundColor(IndexedColors.YELLOW.getIndex());
        estiloCelda.setFillPattern(CellStyle.SOLID_FOREGROUND);
    }/*from   www  .j ava  2s  .  co m*/
    fuente.setFontName("Calibri");
    fuente.setBold(true);
    fuente.setFontHeightInPoints((short) 12);
    estiloCelda.setFont(fuente);
    estiloCelda.setVerticalAlignment(VerticalAlignment.CENTER);
    estiloCelda.setAlignment(HorizontalAlignment.CENTER);
    estiloCelda.setBorderBottom(BorderStyle.THIN);
    estiloCelda.setBorderTop(BorderStyle.THIN);
    estiloCelda.setBorderLeft(BorderStyle.THIN);
    estiloCelda.setBorderRight(BorderStyle.THIN);

    return estiloCelda;
}

From source file:com.catexpress.util.FormatosPOI.java

public CellStyle estiloHeader(Workbook wb, int tipo) {
    Font fuente = wb.createFont();
    CreationHelper createHelper = wb.getCreationHelper();
    fuente.setFontName("Calibri");
    fuente.setBold(true);// www. j  a  v  a 2  s  .co  m

    if (tipo == TITULO || tipo == SUCURSAL || tipo == LABEL || tipo == FECHA) {
        fuente.setFontHeightInPoints((short) 16);
    } else if (tipo == USUARIO) {
        fuente.setFontHeightInPoints((short) 20);
    }

    CellStyle estiloCelda = wb.createCellStyle();
    estiloCelda.setFont(fuente);

    if (tipo == TITULO || tipo == USUARIO || tipo == LABEL || tipo == FECHA) {
        estiloCelda.setFillForegroundColor(IndexedColors.WHITE.getIndex());
    } else if (tipo == SUCURSAL) {
        estiloCelda.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
    }
    estiloCelda.setFillPattern(CellStyle.SOLID_FOREGROUND);

    if (tipo == LABEL || tipo == FECHA) {
        estiloCelda.setWrapText(false);
    } else if (tipo == TITULO || tipo == SUCURSAL || tipo == USUARIO) {
        estiloCelda.setWrapText(true);
    }

    estiloCelda.setAlignment(HorizontalAlignment.CENTER);

    if (tipo == LABEL || tipo == FECHA) {
        estiloCelda.setVerticalAlignment(VerticalAlignment.BOTTOM);
    } else if (tipo == TITULO || tipo == SUCURSAL || tipo == USUARIO) {
        estiloCelda.setVerticalAlignment(VerticalAlignment.CENTER);
    }

    if (tipo == SUCURSAL) {
        estiloCelda.setBorderBottom(BorderStyle.MEDIUM);
        estiloCelda.setBorderTop(BorderStyle.MEDIUM);
        estiloCelda.setBorderLeft(BorderStyle.MEDIUM);
        estiloCelda.setBorderRight(BorderStyle.MEDIUM);
    }

    if (tipo == FECHA) {
        estiloCelda.setDataFormat(createHelper.createDataFormat().getFormat("dd \"de\" mmmm \"de\" yyyy"));
    }

    return estiloCelda;
}

From source file:com.cms.utils.ExportExcellCelltype.java

public CellStyle cellTypeColumnStt() {
    CellStyle cellStyle = wb.createCellStyle();
    cellStyle.setAlignment(CellStyle.ALIGN_CENTER);
    cellStyle.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
    cellStyle.setBorderLeft(CellStyle.BORDER_THIN);
    cellStyle.setBorderBottom(CellStyle.BORDER_THIN);
    cellStyle.setBorderRight(CellStyle.BORDER_THIN);
    cellStyle.setBorderTop(CellStyle.BORDER_THIN);
    cellStyle.setFillForegroundColor(IndexedColors.LIGHT_GREEN.getIndex());
    cellStyle.setFillPattern(CellStyle.SOLID_FOREGROUND);
    cellStyle.setWrapText(false);/*from w ww  .ja  va 2s .co m*/
    return cellStyle;

}

From source file:com.cms.utils.ExportExcellCelltype.java

public CellStyle cellTypeAlignLeft(Boolean wraptext) {

    CellStyle cellStyleLeft = wb.createCellStyle();
    cellStyleLeft.setAlignment(CellStyle.ALIGN_LEFT);
    cellStyleLeft.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
    cellStyleLeft.setBorderLeft(CellStyle.BORDER_THIN);
    cellStyleLeft.setBorderBottom(CellStyle.BORDER_THIN);
    cellStyleLeft.setBorderRight(CellStyle.BORDER_THIN);
    cellStyleLeft.setBorderTop(CellStyle.BORDER_THIN);
    cellStyleLeft.setWrapText(wraptext);
    return cellStyleLeft;

}

From source file:com.cms.utils.ExportExcellCelltype.java

public CellStyle cellTypeAlignCenter(Boolean wraptext) {
    CellStyle cellStyleCenter = wb.createCellStyle();
    cellStyleCenter.setAlignment(CellStyle.ALIGN_CENTER);
    cellStyleCenter.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
    cellStyleCenter.setBorderLeft(CellStyle.BORDER_THIN);
    cellStyleCenter.setBorderBottom(CellStyle.BORDER_THIN);
    cellStyleCenter.setBorderRight(CellStyle.BORDER_THIN);
    cellStyleCenter.setBorderTop(CellStyle.BORDER_THIN);
    cellStyleCenter.setWrapText(wraptext);
    return cellStyleCenter;
}

From source file:com.cms.utils.ExportExcellCelltype.java

public CellStyle cellTypeHeader(Boolean wraptext) {
    CellStyle cellStyle = wb.createCellStyle();
    cellStyle.setAlignment(CellStyle.ALIGN_CENTER);
    cellStyle.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
    cellStyle.setBorderLeft(CellStyle.BORDER_THIN);
    cellStyle.setBorderBottom(CellStyle.BORDER_THIN);
    cellStyle.setBorderRight(CellStyle.BORDER_THIN);
    cellStyle.setBorderTop(CellStyle.BORDER_THIN);
    cellStyle.setFillForegroundColor(IndexedColors.LIGHT_GREEN.getIndex());
    cellStyle.setFillPattern(CellStyle.SOLID_FOREGROUND);
    cellStyle.setWrapText(wraptext);/* ww  w. java2 s .  c o m*/
    return cellStyle;
}

From source file:com.cms.utils.ExportExcellCelltype.java

public CellStyle cellTypeAlignRight(Boolean wraptext) {
    CellStyle cellStyleRight = wb.createCellStyle();
    cellStyleRight.setAlignment(CellStyle.ALIGN_RIGHT);
    cellStyleRight.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
    cellStyleRight.setBorderLeft(CellStyle.BORDER_THIN);
    cellStyleRight.setBorderBottom(CellStyle.BORDER_THIN);
    cellStyleRight.setBorderRight(CellStyle.BORDER_THIN);
    cellStyleRight.setBorderTop(CellStyle.BORDER_THIN);
    cellStyleRight.setWrapText(wraptext);
    return cellStyleRight;
}

From source file:com.company.et.service.XlsService.java

private static void setCellStyle(Workbook wb, Sheet s, Cell cell) {
    CellStyle cellStyle = wb.createCellStyle();
    //        if (cell.getStringCellValue().equals("??")) {
    //            s.autoSizeColumn(0,true);
    //        }/*from w  ww  .j  ava2  s. co  m*/
    cellStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
    cellStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
    Font font = wb.createFont();
    font.setBold(true);
    cellStyle.setFont(font);
    cell.setCellStyle(cellStyle);
}

From source file:com.dituiba.excel.BaseExcelService.java

License:Apache License

/**
 * sheet ?/*from  w  w  w .j  a va  2  s  . co m*/
 * @param sheet
 * @param row
 * @param length
 * @param data
 */
public static void addTitle(Sheet sheet, int row, int length, String data) {
    if (data == null || data.equals("") || data.equals("null")) {
        return;
    }
    Row sheetRow = sheet.createRow(row);
    for (int i = 0; i < length; i++) {
        sheetRow.createCell(i);
    }
    CellStyle style = sheet.getWorkbook().createCellStyle(); // ?
    style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);// 
    style.setAlignment(HSSFCellStyle.ALIGN_CENTER);// 
    CellRangeAddress cellRangeAddress = new CellRangeAddress(row, row, 0, length - 1);
    sheet.addMergedRegion(cellRangeAddress);
    Cell cell = sheetRow.getCell(0);
    cell.setCellStyle(style);
    cell.setCellValue(data);
}