Example usage for org.apache.poi.ss.usermodel VerticalAlignment CENTER

List of usage examples for org.apache.poi.ss.usermodel VerticalAlignment CENTER

Introduction

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

Prototype

VerticalAlignment CENTER

To view the source code for org.apache.poi.ss.usermodel VerticalAlignment CENTER.

Click Source Link

Document

The vertical alignment is centered across the height of the cell.

Usage

From source file:org.pentaho.reporting.engine.classic.core.modules.output.table.xls.helper.ExcelCellStyleBuilderTest.java

License:Open Source License

@Test
public void testElementStyleSet() {
    when(workbook.createCellStyle()).thenReturn(xlsStyle);
    ExcelCellStyleBuilder builder = new ExcelCellStyleBuilder(workbook);
    when(workbook.createCellStyle()).thenReturn(xlsStyle);

    when(styleKey.getHorizontalAlignment()).thenReturn(HorizontalAlignment.CENTER);
    when(styleKey.getVerticalAlignment()).thenReturn(VerticalAlignment.CENTER);
    when(styleKey.isWrapText()).thenReturn(true);
    when(workbook.getFontAt(anyShort())).thenReturn(font);
    when(styleKey.getIndention()).thenReturn((short) 15);

    when(styleKey.getDataStyle()).thenReturn((short) -1);

    builder.withElementStyle(mock(StyleSheet.class), styleKey);

    verify(xlsStyle, times(1)).setAlignment(eq(HorizontalAlignment.CENTER));
    verify(xlsStyle, times(1)).setVerticalAlignment(eq(VerticalAlignment.CENTER));
    verify(xlsStyle, times(1)).setFont(any());
    verify(xlsStyle, times(1)).setWrapText(eq(true));
    verify(xlsStyle, times(1)).setIndention(eq((short) 15));
    verify(xlsStyle, times(0)).setDataFormat(anyShort());
}

From source file:org.pentaho.reporting.engine.classic.core.modules.output.table.xls.helper.HSSFCellStyleProducer.java

License:Open Source License

/**
 * Converts the given element alignment into one of the VerticalAlignment-constants.
 *
 * @param e the JFreeReport element alignment.
 * @return the VerticalAlignment-Alignment.
 * @throws IllegalArgumentException if an Unknown JFreeReport alignment is given.
 *///from  w w w  .j  a v  a 2 s. c om
protected static VerticalAlignment convertVerticalAlignment(final ElementAlignment e) {
    if (ElementAlignment.TOP.equals(e)) {
        return VerticalAlignment.TOP;
    } else if (ElementAlignment.BOTTOM.equals(e)) {
        return VerticalAlignment.BOTTOM;
    } else if (ElementAlignment.MIDDLE.equals(e)) {
        return VerticalAlignment.CENTER;
    }

    throw new IllegalArgumentException("Invalid alignment");
}

From source file:org.tsukuba_bunko.lilac.helper.port.impl.ExportAuthorHelperImpl.java

License:Open Source License

/**
 * @see org.tsukuba_bunko.lilac.helper.port.impl.ExportDataHelperBase#prepare(org.apache.poi.xssf.usermodel.XSSFWorkbook)
 *//*from  w w w. jav a 2 s .c o m*/
@Override
protected void prepare(XSSFWorkbook book) {
    flagCellStyle = book.createCellStyle();
    flagCellStyle.setAlignment(HorizontalAlignment.CENTER);
    flagCellStyle.setVerticalAlignment(VerticalAlignment.CENTER);

    idCellStyle = book.createCellStyle();

    commonCellStyle = book.createCellStyle();
    commonCellStyle.setAlignment(HorizontalAlignment.LEFT);
    commonCellStyle.setVerticalAlignment(VerticalAlignment.TOP);

    noteCellStyle = book.createCellStyle();
    XSSFFont noteFont = book.createFont();
    noteFont.setFontHeightInPoints((short) 9);
    noteCellStyle.setFont(noteFont);
    noteCellStyle.setAlignment(HorizontalAlignment.LEFT);
    noteCellStyle.setVerticalAlignment(VerticalAlignment.TOP);
    noteCellStyle.setWrapText(true);
}

From source file:org.tsukuba_bunko.lilac.helper.port.impl.ExportBibliographyHelperImpl.java

License:Open Source License

/**
 * @see org.tsukuba_bunko.lilac.helper.port.impl.ExportDataHelperBase#prepare(org.apache.poi.xssf.usermodel.XSSFWorkbook)
 *///from   ww w. j  a va 2s  . co m
@Override
protected void prepare(XSSFWorkbook book) {
    flagCellStyle = book.createCellStyle();
    flagCellStyle.setAlignment(HorizontalAlignment.CENTER);
    flagCellStyle.setVerticalAlignment(VerticalAlignment.CENTER);

    idCellStyle = book.createCellStyle();

    commonCellStyle = book.createCellStyle();
    commonCellStyle.setAlignment(HorizontalAlignment.LEFT);
    commonCellStyle.setVerticalAlignment(VerticalAlignment.TOP);

    authorsCellStyle = book.createCellStyle();
    authorsCellStyle.setWrapText(true);
    authorsCellStyle.setAlignment(HorizontalAlignment.LEFT);
    authorsCellStyle.setVerticalAlignment(VerticalAlignment.TOP);

    dateCellStyle = book.createCellStyle();
    dateCellStyle.setAlignment(HorizontalAlignment.LEFT);
    dateCellStyle.setVerticalAlignment(VerticalAlignment.TOP);
}

From source file:org.tsukuba_bunko.lilac.helper.port.impl.ExportBookHelperImpl.java

License:Open Source License

/**
 * @see org.tsukuba_bunko.lilac.helper.port.impl.ExportDataHelperBase#prepare(org.apache.poi.xssf.usermodel.XSSFWorkbook)
 *//*from w  w  w.  j  av a  2  s  .  c  o m*/
@Override
protected void prepare(XSSFWorkbook book) {
    flagCellStyle = book.createCellStyle();
    flagCellStyle.setAlignment(HorizontalAlignment.CENTER);
    flagCellStyle.setVerticalAlignment(VerticalAlignment.CENTER);

    idCellStyle = book.createCellStyle();
    XSSFFont idFont = book.createFont();
    idFont.setFontHeightInPoints((short) 9);
    idCellStyle.setFont(idFont);

    commonCellStyle = book.createCellStyle();
    commonCellStyle.setAlignment(HorizontalAlignment.LEFT);
    commonCellStyle.setVerticalAlignment(VerticalAlignment.TOP);

    dateCellStyle = book.createCellStyle();
    dateCellStyle.setAlignment(HorizontalAlignment.LEFT);
    dateCellStyle.setVerticalAlignment(VerticalAlignment.TOP);
}

From source file:org.tsukuba_bunko.lilac.helper.port.impl.ExportBookshelfHelperImpl.java

License:Open Source License

/**
 * @see org.tsukuba_bunko.lilac.helper.port.impl.ExportDataHelperBase#prepare(org.apache.poi.xssf.usermodel.XSSFWorkbook)
 *///w  w  w.  ja v  a 2 s. c  o  m
@Override
protected void prepare(XSSFWorkbook book) {
    flagCellStyle = book.createCellStyle();
    flagCellStyle.setAlignment(HorizontalAlignment.CENTER);
    flagCellStyle.setVerticalAlignment(VerticalAlignment.CENTER);

    idCellStyle = book.createCellStyle();

    noteCellStyle = book.createCellStyle();
    XSSFFont noteFont = book.createFont();
    noteFont.setFontHeightInPoints((short) 9);
    noteCellStyle.setFont(noteFont);
    noteCellStyle.setAlignment(HorizontalAlignment.LEFT);
    noteCellStyle.setVerticalAlignment(VerticalAlignment.TOP);
    noteCellStyle.setWrapText(true);
}

From source file:org.tsukuba_bunko.lilac.helper.port.impl.ExportDataHelperBase.java

License:Open Source License

/**
 * @see org.tsukuba_bunko.lilac.helper.port.ExportDataHelper#exportData(org.apache.poi.xssf.usermodel.XSSFWorkbook)
 *///from  ww  w.j  a  v a  2 s.  c  o  m
@Override
public void exportData(XSSFWorkbook book) {
    sheet = book.createSheet(getSheetName());

    XSSFFont font = book.createFont();
    font.setBold(true);
    font.setColor(IndexedColors.WHITE.index);

    headerCellStyle = book.createCellStyle();
    headerCellStyle.setAlignment(HorizontalAlignment.CENTER);
    headerCellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
    headerCellStyle
            .setFillForegroundColor(new XSSFColor(new byte[] { (byte) 256, (byte) 0, (byte) 112, (byte) 192 }));
    headerCellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
    headerCellStyle.setFont(font);

    prepare(book);

    XSSFRow row = sheet.createRow(rowCount++);
    processHeaderRow(row);

    buildQuery().iterate(this);
    finish(book);
}

From source file:org.tsukuba_bunko.lilac.helper.port.impl.ExportLabelHelperImpl.java

License:Open Source License

/**
 * @see org.tsukuba_bunko.lilac.helper.port.impl.ExportDataHelperBase#prepare(org.apache.poi.xssf.usermodel.XSSFWorkbook)
 *///w w w  .java  2 s  . co m
@Override
protected void prepare(XSSFWorkbook book) {
    flagCellStyle = book.createCellStyle();
    flagCellStyle.setAlignment(HorizontalAlignment.CENTER);
    flagCellStyle.setVerticalAlignment(VerticalAlignment.CENTER);

    noteCellStyle = book.createCellStyle();
    XSSFFont noteFont = book.createFont();
    noteFont.setFontHeightInPoints((short) 9);
    noteCellStyle.setFont(noteFont);
    noteCellStyle.setAlignment(HorizontalAlignment.LEFT);
    noteCellStyle.setVerticalAlignment(VerticalAlignment.TOP);
    noteCellStyle.setWrapText(true);
}

From source file:org.zafritech.zidingorms.io.excel.ExcelFunctions.java

private static Map<String, CellStyle> createStyles(Workbook wb) {

    Map<String, CellStyle> styles = new HashMap<String, CellStyle>();
    CreationHelper creationHelper = wb.getCreationHelper();

    CellStyle style;/*from w w  w.j  a  v  a2s  .c  om*/

    // Header Font
    Font headerFont = wb.createFont();
    headerFont.setFontHeightInPoints((short) 12);
    headerFont.setBold(true);
    headerFont.setColor(IndexedColors.WHITE.getIndex());

    // Header Left Aligned Style
    style = createBorderedStyle(wb);
    style.setAlignment(HorizontalAlignment.LEFT);
    style.setVerticalAlignment(VerticalAlignment.CENTER);
    style.setFont(headerFont);
    style.setFillForegroundColor(IndexedColors.PALE_BLUE.getIndex());
    style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
    styles.put("HeaderLeftAlign", style);

    // Header Center Aligned Style
    style = createBorderedStyle(wb);
    style.setAlignment(HorizontalAlignment.CENTER);
    style.setVerticalAlignment(VerticalAlignment.CENTER);
    style.setFont(headerFont);
    style.setFillForegroundColor(IndexedColors.PALE_BLUE.getIndex());
    style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
    styles.put("HeaderCenterAlign", style);

    // Body Left Aligned Style
    style = createBorderedStyle(wb);
    style.setAlignment(HorizontalAlignment.LEFT);
    style.setVerticalAlignment(VerticalAlignment.TOP);
    styles.put("BodyLeftAlign", style);

    // Body Center Aligned Style
    style = createBorderedStyle(wb);
    style.setAlignment(HorizontalAlignment.CENTER);
    style.setVerticalAlignment(VerticalAlignment.TOP);
    styles.put("BodyCenterAlign", style);

    // Body Left Aligned WrapText Style
    style = createBorderedStyle(wb);
    style.setAlignment(HorizontalAlignment.LEFT);
    style.setVerticalAlignment(VerticalAlignment.TOP);
    style.setWrapText(true);
    styles.put("BodyLeftAlignWrapText", style);

    // Body Left Aligned Date Format Style
    style = createBorderedStyle(wb);
    style.setAlignment(HorizontalAlignment.LEFT);
    style.setVerticalAlignment(VerticalAlignment.TOP);
    style.setDataFormat(creationHelper.createDataFormat().getFormat("yyyy-MM-dd HH:mm:ss"));
    styles.put("BodyLeftAlignDate", style);

    // Body Center Aligned Date Format Style
    style = createBorderedStyle(wb);
    style.setAlignment(HorizontalAlignment.CENTER);
    style.setVerticalAlignment(VerticalAlignment.TOP);
    style.setDataFormat(creationHelper.createDataFormat().getFormat("yyyy-MM-dd HH:mm:ss"));
    styles.put("BodyCenterAlignDate", style);

    return styles;
}

From source file:packtest.CalendarDemo.java

License:Apache License

/**
 * cell styles used for formatting calendar sheets
 */// www .  j  a va  2 s  .c o  m
private static Map<String, XSSFCellStyle> createStyles(XSSFWorkbook wb) {
    Map<String, XSSFCellStyle> styles = new HashMap<String, XSSFCellStyle>();

    XSSFCellStyle style;
    XSSFFont titleFont = wb.createFont();
    titleFont.setFontHeightInPoints((short) 48);
    titleFont.setColor(new XSSFColor(new java.awt.Color(39, 51, 89)));
    style = wb.createCellStyle();
    style.setAlignment(HorizontalAlignment.CENTER);
    style.setVerticalAlignment(VerticalAlignment.CENTER);
    style.setFont(titleFont);
    styles.put("title", style);

    XSSFFont monthFont = wb.createFont();
    monthFont.setFontHeightInPoints((short) 12);
    monthFont.setColor(new XSSFColor(new java.awt.Color(255, 255, 255)));
    monthFont.setBold(true);
    style = wb.createCellStyle();
    style.setAlignment(HorizontalAlignment.CENTER);
    style.setVerticalAlignment(VerticalAlignment.CENTER);
    style.setFillForegroundColor(new XSSFColor(new java.awt.Color(39, 51, 89)));
    style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
    style.setFont(monthFont);
    styles.put("month", style);

    XSSFFont dayFont = wb.createFont();
    dayFont.setFontHeightInPoints((short) 14);
    dayFont.setBold(true);
    style = wb.createCellStyle();
    style.setAlignment(HorizontalAlignment.LEFT);
    style.setVerticalAlignment(VerticalAlignment.TOP);
    style.setFillForegroundColor(new XSSFColor(new java.awt.Color(228, 232, 243)));
    style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
    style.setBorderLeft(BorderStyle.THIN);
    style.setLeftBorderColor(new XSSFColor(new java.awt.Color(39, 51, 89)));
    style.setBorderBottom(BorderStyle.THIN);
    style.setBottomBorderColor(new XSSFColor(new java.awt.Color(39, 51, 89)));
    style.setFont(dayFont);
    styles.put("weekend_left", style);

    style = wb.createCellStyle();
    style.setAlignment(HorizontalAlignment.CENTER);
    style.setVerticalAlignment(VerticalAlignment.TOP);
    style.setFillForegroundColor(new XSSFColor(new java.awt.Color(228, 232, 243)));
    style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
    style.setBorderRight(BorderStyle.THIN);
    style.setRightBorderColor(new XSSFColor(new java.awt.Color(39, 51, 89)));
    style.setBorderBottom(BorderStyle.THIN);
    style.setBottomBorderColor(new XSSFColor(new java.awt.Color(39, 51, 89)));
    styles.put("weekend_right", style);

    style = wb.createCellStyle();
    style.setAlignment(HorizontalAlignment.LEFT);
    style.setVerticalAlignment(VerticalAlignment.TOP);
    style.setBorderLeft(BorderStyle.THIN);
    style.setFillForegroundColor(new XSSFColor(new java.awt.Color(255, 255, 255)));
    style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
    style.setLeftBorderColor(new XSSFColor(new java.awt.Color(39, 51, 89)));
    style.setBorderBottom(BorderStyle.THIN);
    style.setBottomBorderColor(new XSSFColor(new java.awt.Color(39, 51, 89)));
    style.setFont(dayFont);
    styles.put("workday_left", style);

    style = wb.createCellStyle();
    style.setAlignment(HorizontalAlignment.CENTER);
    style.setVerticalAlignment(VerticalAlignment.TOP);
    style.setFillForegroundColor(new XSSFColor(new java.awt.Color(255, 255, 255)));
    style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
    style.setBorderRight(BorderStyle.THIN);
    style.setRightBorderColor(new XSSFColor(new java.awt.Color(39, 51, 89)));
    style.setBorderBottom(BorderStyle.THIN);
    style.setBottomBorderColor(new XSSFColor(new java.awt.Color(39, 51, 89)));
    styles.put("workday_right", style);

    style = wb.createCellStyle();
    style.setBorderLeft(BorderStyle.THIN);
    style.setFillForegroundColor(new XSSFColor(new java.awt.Color(234, 234, 234)));
    style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
    style.setBorderBottom(BorderStyle.THIN);
    style.setBottomBorderColor(new XSSFColor(new java.awt.Color(39, 51, 89)));
    styles.put("grey_left", style);

    style = wb.createCellStyle();
    style.setFillForegroundColor(new XSSFColor(new java.awt.Color(234, 234, 234)));
    style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
    style.setBorderRight(BorderStyle.THIN);
    style.setRightBorderColor(new XSSFColor(new java.awt.Color(39, 51, 89)));
    style.setBorderBottom(BorderStyle.THIN);
    style.setBottomBorderColor(new XSSFColor(new java.awt.Color(39, 51, 89)));
    styles.put("grey_right", style);

    return styles;
}