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:cn.afterturn.easypoi.excel.export.styler.ExcelExportStylerDefaultImpl.java

License:Apache License

@Override
public CellStyle getHeaderStyle(short color) {
    CellStyle titleStyle = workbook.createCellStyle();
    Font font = workbook.createFont();
    font.setFontHeightInPoints((short) 12);
    titleStyle.setFont(font);/*from w w w. j ava2s  . c  om*/
    titleStyle.setAlignment(HorizontalAlignment.CENTER);
    titleStyle.setVerticalAlignment(VerticalAlignment.CENTER);
    return titleStyle;
}

From source file:cn.afterturn.easypoi.excel.export.styler.ExcelExportStylerDefaultImpl.java

License:Apache License

@Override
public CellStyle stringNoneStyle(Workbook workbook, boolean isWarp) {
    CellStyle style = workbook.createCellStyle();
    style.setAlignment(HorizontalAlignment.CENTER);
    style.setVerticalAlignment(VerticalAlignment.CENTER);
    style.setDataFormat(STRING_FORMAT);/*from w ww. j  a  v  a 2s .  c o  m*/
    if (isWarp) {
        style.setWrapText(true);
    }
    return style;
}

From source file:cn.bzvs.excel.export.ExcelExportServer.java

License:Apache License

/**
 *  ?//from ww w . j  ava  2 s . c om
 * 
 * @param entity
 * @param sheet
 * @param workbook
 * @param feildWidth
 */
public int createHeaderRow(ExportParams entity, Sheet sheet, Workbook workbook, int feildWidth) {
    Row row = sheet.createRow(0);
    row.setHeight(entity.getTitleHeight());
    createStringCell(row, 0, entity.getTitle(), getExcelExportStyler().getHeaderStyle(entity.getHeaderColor()),
            null);
    for (int i = 1; i <= feildWidth; i++) {
        createStringCell(row, i, "", getExcelExportStyler().getHeaderStyle(entity.getHeaderColor()), null);
    }
    sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, feildWidth));
    if (entity.getSecondTitle() != null) {
        row = sheet.createRow(1);
        row.setHeight(entity.getSecondTitleHeight());
        CellStyle style = workbook.createCellStyle();
        style.setAlignment(CellStyle.ALIGN_RIGHT);
        createStringCell(row, 0, entity.getSecondTitle(), style, null);
        for (int i = 1; i <= feildWidth; i++) {
            createStringCell(row, i, "", getExcelExportStyler().getHeaderStyle(entity.getHeaderColor()), null);
        }
        sheet.addMergedRegion(new CellRangeAddress(1, 1, 0, feildWidth));
        return 2;
    }
    return 1;
}

From source file:cn.bzvs.excel.export.styler.ExcelExportStylerBorderImpl.java

License:Apache License

@Override
public CellStyle getHeaderStyle(short color) {
    CellStyle titleStyle = workbook.createCellStyle();
    Font font = workbook.createFont();
    font.setFontHeightInPoints((short) 12);
    titleStyle.setFont(font);//  ww w.  j a v a 2  s . c o  m
    titleStyle.setBorderLeft((short) 1); // 
    titleStyle.setBorderRight((short) 1); // ?
    titleStyle.setBorderBottom((short) 1);
    titleStyle.setBorderTop((short) 1);
    titleStyle.setAlignment(CellStyle.ALIGN_CENTER);
    titleStyle.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
    return titleStyle;
}

From source file:cn.bzvs.excel.export.styler.ExcelExportStylerBorderImpl.java

License:Apache License

@Override
public CellStyle stringNoneStyle(Workbook workbook, boolean isWarp) {
    CellStyle style = workbook.createCellStyle();
    style.setBorderLeft((short) 1); // 
    style.setBorderRight((short) 1); // ?
    style.setBorderBottom((short) 1);
    style.setBorderTop((short) 1);
    style.setAlignment(CellStyle.ALIGN_CENTER);
    style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
    style.setDataFormat(STRING_FORMAT);//  w  w w. ja  va  2s  . c  o m
    if (isWarp) {
        style.setWrapText(true);
    }
    return style;
}

From source file:cn.bzvs.excel.export.styler.ExcelExportStylerBorderImpl.java

License:Apache License

@Override
public CellStyle getTitleStyle(short color) {
    CellStyle titleStyle = workbook.createCellStyle();
    titleStyle.setBorderLeft((short) 1); // 
    titleStyle.setBorderRight((short) 1); // ?
    titleStyle.setBorderBottom((short) 1);
    titleStyle.setBorderTop((short) 1);
    titleStyle.setAlignment(CellStyle.ALIGN_CENTER);
    titleStyle.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
    titleStyle.setWrapText(true);/*from ww  w  . j  a  v  a  2  s  .c om*/
    return titleStyle;
}

From source file:cn.bzvs.excel.export.styler.ExcelExportStylerColorImpl.java

License:Apache License

@Override
public CellStyle getHeaderStyle(short headerColor) {
    CellStyle titleStyle = workbook.createCellStyle();
    Font font = workbook.createFont();
    font.setFontHeightInPoints((short) 24);
    titleStyle.setFont(font);/*  w w w.  jav a2  s .co m*/
    titleStyle.setFillForegroundColor(headerColor);
    titleStyle.setAlignment(CellStyle.ALIGN_CENTER);
    titleStyle.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
    return titleStyle;
}

From source file:cn.bzvs.excel.export.styler.ExcelExportStylerColorImpl.java

License:Apache License

@Override
public CellStyle getTitleStyle(short color) {
    CellStyle titleStyle = workbook.createCellStyle();
    titleStyle.setFillForegroundColor(color); // 
    titleStyle.setAlignment(CellStyle.ALIGN_CENTER);
    titleStyle.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
    titleStyle.setFillPattern(CellStyle.SOLID_FOREGROUND); // 
    titleStyle.setWrapText(true);/*from w  ww  . java  2 s . co  m*/
    return titleStyle;
}

From source file:cn.bzvs.excel.export.styler.ExcelExportStylerColorImpl.java

License:Apache License

@Override
public CellStyle stringSeptailStyle(Workbook workbook, boolean isWarp) {
    CellStyle style = workbook.createCellStyle();
    style.setBorderLeft((short) 1); // 
    style.setBorderRight((short) 1); // ?
    style.setBorderBottom((short) 1);
    style.setBorderTop((short) 1);
    style.setFillForegroundColor((short) 41); // 
    style.setFillPattern(CellStyle.SOLID_FOREGROUND); // 
    style.setAlignment(CellStyle.ALIGN_CENTER);
    style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
    style.setDataFormat(STRING_FORMAT);//from www .  ja  va 2 s. c o m
    if (isWarp) {
        style.setWrapText(true);
    }
    return style;
}

From source file:cn.bzvs.excel.export.styler.ExcelExportStylerDefaultImpl.java

License:Apache License

@Override
public CellStyle getTitleStyle(short color) {
    CellStyle titleStyle = workbook.createCellStyle();
    titleStyle.setAlignment(CellStyle.ALIGN_CENTER);
    titleStyle.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
    titleStyle.setWrapText(true);//from w w w .  j  a  v  a  2 s  . co m
    return titleStyle;
}