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:vista.ui.VistaGenerarEstadisticas.java

License:Open Source License

/**
 * Este mtodo sirve para crear un estilo de celda bsico con un estilo de
 * borde y color para borde//from w  w w .j av  a2s.  c om
 *
 * @param workbook el objeto Workbook dueo de la celda
 * @param borderColor el color del borde
 * @param borderStyle el estilo del borde
 * @param halign la alineacin horizontal de la celda o un nmero negativo
 * si no se desea tener alineacin horizontal
 * @param valign la alineacin vertical de la celda o un nmero negativo si
 * no se desea tener alineacin vertical
 *
 * @return un objeto CellStyle con el estilo de la celda creado
 */
private CellStyle crearEstiloCelda(Workbook workbook, IndexedColors borderColor, short borderStyle,
        short halign, short valign) {
    CellStyle style = workbook.createCellStyle();

    //Estilo centrado y con bordes
    style.setBorderBottom(borderStyle);
    style.setBottomBorderColor(borderColor.getIndex());
    style.setBorderLeft(borderStyle);
    style.setLeftBorderColor(borderColor.getIndex());
    style.setBorderRight(borderStyle);
    style.setRightBorderColor(borderColor.getIndex());
    style.setBorderTop(borderStyle);
    style.setTopBorderColor(borderColor.getIndex());

    if (halign >= 0) {
        style.setAlignment(halign);
        style.setVerticalAlignment(valign);
    }

    return style;
}

From source file:vistas.reportes.procesos.rptVacacionesExcel.java

private Map<String, CellStyle> createStyles(Workbook wb) {
    Map<String, CellStyle> styles = new HashMap<String, CellStyle>();
    CellStyle style;
    Font titleFont = wb.createFont();
    titleFont.setFontHeightInPoints((short) 18);
    titleFont.setBoldweight(Font.BOLDWEIGHT_BOLD);
    style = wb.createCellStyle();/* www  .  j a va2 s . c  o m*/
    style.setAlignment(CellStyle.ALIGN_CENTER);
    style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
    style.setFont(titleFont);
    styles.put("title", style);

    Font monthFont = wb.createFont();
    monthFont.setFontHeightInPoints((short) 11);
    monthFont.setColor(IndexedColors.WHITE.getIndex());
    style = wb.createCellStyle();
    style.setAlignment(CellStyle.ALIGN_CENTER);
    style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
    style.setFillForegroundColor(IndexedColors.GREY_50_PERCENT.getIndex());
    style.setFillPattern(CellStyle.SOLID_FOREGROUND);
    style.setFont(monthFont);
    style.setWrapText(true);
    styles.put("header", style);

    style = wb.createCellStyle();
    style.setAlignment(CellStyle.ALIGN_CENTER);
    style.setWrapText(true);
    style.setBorderRight(CellStyle.BORDER_THIN);
    style.setRightBorderColor(IndexedColors.BLACK.getIndex());
    style.setBorderLeft(CellStyle.BORDER_THIN);
    style.setLeftBorderColor(IndexedColors.BLACK.getIndex());
    style.setBorderTop(CellStyle.BORDER_THIN);
    style.setTopBorderColor(IndexedColors.BLACK.getIndex());
    style.setBorderBottom(CellStyle.BORDER_THIN);
    style.setBottomBorderColor(IndexedColors.BLACK.getIndex());
    styles.put("cell", style);

    style = wb.createCellStyle();
    style.setAlignment(CellStyle.ALIGN_CENTER);
    style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
    style.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
    style.setFillPattern(CellStyle.SOLID_FOREGROUND);
    style.setDataFormat(wb.createDataFormat().getFormat("0.00"));
    styles.put("formula", style);

    style = wb.createCellStyle();
    style.setAlignment(CellStyle.ALIGN_CENTER);
    style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
    style.setFillForegroundColor(IndexedColors.GREY_40_PERCENT.getIndex());
    style.setFillPattern(CellStyle.SOLID_FOREGROUND);
    style.setDataFormat(wb.createDataFormat().getFormat("0.00"));
    styles.put("formula_2", style);

    return styles;
}

From source file:workbench.db.exporter.XlsRowDataConverter.java

License:Apache License

private void writeInfoSheet() {
    Sheet info = workbook.getSheet(INFO_SHEETNAME);

    if (info == null) {
        info = workbook.createSheet(INFO_SHEETNAME);
        Row headRow = info.createRow(0);
        Cell cell = headRow.createCell(0);
        setCellValueAndStyle(cell, ResourceMgr.getString("TxtSheet"), true, false, 0);
        cell = headRow.createCell(1);/*www  .  j av a2s  . co  m*/
        setCellValueAndStyle(cell, "SQL", true, false, 1);
    } else {
        // move the info sheet to the end
        int count = workbook.getNumberOfSheets();
        workbook.setSheetOrder(info.getSheetName(), count - 1);
    }

    int rowNum = info.getLastRowNum() + 1;

    Row infoRow = info.createRow(rowNum);

    Cell name = infoRow.createCell(0);
    CellStyle nameStyle = workbook.createCellStyle();
    nameStyle.setAlignment(CellStyle.ALIGN_LEFT);
    nameStyle.setVerticalAlignment(CellStyle.VERTICAL_TOP);
    nameStyle.setWrapText(false);
    name.setCellValue(sheet.getSheetName());
    name.setCellStyle(nameStyle);
    info.autoSizeColumn(0);

    Cell sqlCell = infoRow.createCell(1);
    CellStyle sqlStyle = workbook.createCellStyle();
    sqlStyle.setAlignment(CellStyle.ALIGN_LEFT);
    sqlStyle.setVerticalAlignment(CellStyle.VERTICAL_TOP);
    sqlStyle.setWrapText(false);

    RichTextString s = workbook.getCreationHelper().createRichTextString(generatingSql);
    sqlCell.setCellValue(s);
    sqlCell.setCellStyle(sqlStyle);
}