Example usage for org.apache.poi.ss.usermodel Workbook createCellStyle

List of usage examples for org.apache.poi.ss.usermodel Workbook createCellStyle

Introduction

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

Prototype

CellStyle createCellStyle();

Source Link

Document

Create a new Cell style and add it to the workbook's style table

Usage

From source file:com.globalsight.everest.webapp.pagehandler.administration.reports.TranslationProgressReportHelper.java

License:Apache License

private CellStyle getPercentStyle(Workbook p_workbook) throws Exception {
    if (percentStyle == null) {
        DataFormat format = p_workbook.createDataFormat();
        CellStyle style = p_workbook.createCellStyle();
        Font font = p_workbook.createFont();
        font.setFontName("Arial");
        font.setFontHeightInPoints((short) 10);
        style.setDataFormat(format.getFormat("0%"));
        style.setFont(font);//from w  w  w . j  av  a  2 s  . c  o m
        style.setWrapText(true);
        style.setAlignment(CellStyle.ALIGN_LEFT);

        percentStyle = style;
    }

    return percentStyle;
}

From source file:com.globalsight.everest.webapp.pagehandler.administration.reports.VendorPOXlsReport.java

License:Apache License

private void addTitle(Workbook p_workbook, Sheet p_sheet) throws Exception {
    // title font is black bold on white
    String EMEA = CompanyWrapper.getCurrentCompanyName();
    Font titleFont = p_workbook.createFont();
    titleFont.setUnderline(Font.U_NONE);
    titleFont.setFontName("Arial");
    titleFont.setFontHeightInPoints((short) 14);
    titleFont.setBoldweight(Font.BOLDWEIGHT_BOLD);
    titleFont.setColor(IndexedColors.BLACK.getIndex());
    CellStyle titleStyle = p_workbook.createCellStyle();
    titleStyle.setWrapText(false);//  w ww  . java  2  s .  c o m
    titleStyle.setFont(titleFont);

    Row titleRow = getRow(p_sheet, 0);
    Cell cell_A_Title = getCell(titleRow, 0);
    cell_A_Title.setCellValue(EMEA + " " + bundle.getString("lb_po"));
    cell_A_Title.setCellStyle(titleStyle);
    p_sheet.setColumnWidth(0, 20 * 256);
}

From source file:com.globalsight.everest.webapp.pagehandler.administration.reports.VendorPOXlsReport.java

License:Apache License

private CellStyle getRedCellStyle(Workbook p_workbook) throws Exception {
    if (redCellStyle == null) {
        Font redFont = p_workbook.createFont();
        redFont.setFontName("Arial");
        redFont.setUnderline(Font.U_NONE);
        redFont.setFontHeightInPoints((short) 10);

        CellStyle style = p_workbook.createCellStyle();
        style.setFont(redFont);//from   w w  w .j a v  a  2s.  c o  m
        style.setWrapText(true);
        style.setFillPattern(CellStyle.SOLID_FOREGROUND);
        style.setFillForegroundColor(IndexedColors.RED.getIndex());

        redCellStyle = style;
    }
    return redCellStyle;
}

From source file:com.globalsight.everest.webapp.pagehandler.administration.reports.VendorPOXlsReport.java

License:Apache License

private CellStyle getDateStyle(Workbook p_workbook) throws Exception {
    if (dateStyle == null) {
        Font dateFont = p_workbook.createFont();
        dateFont.setFontName("Arial");
        dateFont.setFontHeightInPoints((short) 10);

        DataFormat format = p_workbook.createDataFormat();
        CellStyle cs = p_workbook.createCellStyle();
        cs.setFont(dateFont);// w w w . j  a  v a  2  s  .  c o m
        cs.setDataFormat(format.getFormat("M/d/yy"));
        cs.setWrapText(false);

        dateStyle = cs;
    }
    return dateStyle;
}

From source file:com.globalsight.everest.webapp.pagehandler.administration.reports.VendorPOXlsReport.java

License:Apache License

private CellStyle getFailedDateStyle(Workbook p_workbook) throws Exception {
    if (failedDateStyle == null) {
        Font dateFont = p_workbook.createFont();
        dateFont.setFontName("Arial");
        dateFont.setFontHeightInPoints((short) 10);

        DataFormat format = p_workbook.createDataFormat();
        CellStyle cs = p_workbook.createCellStyle();
        cs.setFont(dateFont);// www .ja  va2s.  c  o m
        cs.setDataFormat(format.getFormat("M/d/yy"));
        cs.setWrapText(false);
        cs.setFillPattern(CellStyle.SOLID_FOREGROUND);
        cs.setFillForegroundColor(IndexedColors.RED.getIndex());

        failedDateStyle = cs;
    }
    return failedDateStyle;
}

From source file:com.globalsight.everest.webapp.pagehandler.administration.reports.VendorPOXlsReport.java

License:Apache License

private CellStyle getMoneyStyle(Workbook p_workbook) throws Exception {
    if (moneyStyle == null) {
        String euroJavaNumberFormat = getNumberFormatString();
        DataFormat euroNumberFormat = p_workbook.createDataFormat();

        CellStyle cs = p_workbook.createCellStyle();
        cs.setDataFormat(euroNumberFormat.getFormat(euroJavaNumberFormat));
        cs.setWrapText(false);//from   w  w w. j a v  a  2s. co m

        moneyStyle = cs;
    }
    return moneyStyle;
}

From source file:com.globalsight.everest.webapp.pagehandler.administration.reports.VendorPOXlsReport.java

License:Apache License

private CellStyle getFailedMoneyStyle(Workbook p_workbook) throws Exception {
    if (failedMoneyStyle == null) {
        String euroJavaNumberFormat = getNumberFormatString();
        DataFormat euroNumberFormat = p_workbook.createDataFormat();

        CellStyle cs = p_workbook.createCellStyle();
        cs.setWrapText(false);/*from w w  w .ja  va  2 s.c  om*/
        cs.setDataFormat(euroNumberFormat.getFormat(euroJavaNumberFormat));
        cs.setFillPattern(CellStyle.SOLID_FOREGROUND);
        cs.setFillForegroundColor(IndexedColors.RED.getIndex());

        failedMoneyStyle = cs;
    }
    return failedMoneyStyle;
}

From source file:com.globalsight.everest.webapp.pagehandler.administration.reports.VendorPOXlsReport.java

License:Apache License

private CellStyle getTotalMoneyStyle(Workbook p_workbook) throws Exception {
    if (totalMoneyStyle == null) {
        String euroJavaNumberFormat = getNumberFormatString();
        DataFormat euroNumberFormat = p_workbook.createDataFormat();
        CellStyle cs = p_workbook.createCellStyle();
        cs.setDataFormat(euroNumberFormat.getFormat(euroJavaNumberFormat));
        cs.setWrapText(false);/*ww  w . j av  a2 s .  co  m*/
        cs.setBorderTop(CellStyle.BORDER_THIN);
        cs.setBorderBottom(CellStyle.BORDER_THIN);
        cs.setFillPattern(CellStyle.SOLID_FOREGROUND);
        cs.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());

        totalMoneyStyle = cs;
    }
    return totalMoneyStyle;
}

From source file:com.griffinslogistics.document.excel.BDLGenerator.java

private static Map<String, CellStyle> createStyles(Workbook workbook) {
    Map<String, CellStyle> styles = new HashMap<String, CellStyle>();
    CellStyle style;/*  w  w  w.  j ava 2  s .c o  m*/
    Font titleFont = workbook.createFont();
    titleFont.setFontHeightInPoints((short) 26);
    titleFont.setFontName("Calibri");
    titleFont.setBoldweight(Font.BOLDWEIGHT_BOLD);
    style = workbook.createCellStyle();
    style.setFont(titleFont);
    style.setAlignment(CellStyle.ALIGN_CENTER);
    styles.put("title", style);

    titleFont = workbook.createFont();
    titleFont.setFontHeightInPoints((short) 18);
    titleFont.setFontName("Calibri");
    style = workbook.createCellStyle();
    style.setFont(titleFont);
    style.setAlignment(CellStyle.ALIGN_JUSTIFY);

    styles.put("pulsioName", style);

    titleFont = workbook.createFont();
    titleFont.setFontHeightInPoints((short) 14);
    titleFont.setFontName("Calibri");
    style = workbook.createCellStyle();
    style.setFont(titleFont);
    style.setAlignment(CellStyle.ALIGN_JUSTIFY);

    styles.put("contacts", style);

    CellStyle footerStyle = workbook.createCellStyle();
    Font footerFont = workbook.createFont();
    footerFont.setFontHeightInPoints((short) 14);
    footerFont.setFontName("Calibri");
    footerFont.setBoldweight(Font.BOLDWEIGHT_BOLD);
    footerStyle.setFont(footerFont);
    footerStyle.setAlignment(CellStyle.ALIGN_JUSTIFY);

    styles.put("footer", footerStyle);

    titleFont = workbook.createFont();
    titleFont.setFontHeightInPoints((short) 14);
    titleFont.setFontName("Calibri");
    titleFont.setBoldweight(Font.BOLDWEIGHT_BOLD);
    titleFont.setItalic(true);
    style = workbook.createCellStyle();
    style.setFont(titleFont);
    style.setAlignment(CellStyle.ALIGN_CENTER);
    style.setWrapText(true);

    style.setFillForegroundColor(HSSFColor.GREY_25_PERCENT.index);
    style.setFillPattern(CellStyle.SOLID_FOREGROUND);
    style.setBorderLeft(CellStyle.BORDER_MEDIUM);
    style.setBorderTop(CellStyle.BORDER_MEDIUM);
    style.setBorderRight(CellStyle.BORDER_THIN);
    style.setBorderBottom(CellStyle.BORDER_THIN);

    styles.put("tableHeadersLeft", style);

    CellStyle headerRowMiddleCellStyle = workbook.createCellStyle();
    headerRowMiddleCellStyle.cloneStyleFrom(style);
    headerRowMiddleCellStyle.setBorderLeft(CellStyle.BORDER_THIN);

    styles.put("tableHeadersMiddle", headerRowMiddleCellStyle);

    CellStyle headerRowRightCellStyle = workbook.createCellStyle();
    headerRowRightCellStyle.cloneStyleFrom(style);
    headerRowRightCellStyle.setBorderRight(CellStyle.BORDER_MEDIUM);

    styles.put("tableHeadersRight", headerRowRightCellStyle);

    CellStyle footerRowRightCellStyle = workbook.createCellStyle();
    footerRowRightCellStyle.cloneStyleFrom(style);
    footerRowRightCellStyle.setFillPattern(CellStyle.NO_FILL);
    footerRowRightCellStyle.setBorderRight(CellStyle.BORDER_MEDIUM);
    footerRowRightCellStyle.setBorderBottom(CellStyle.BORDER_MEDIUM);

    styles.put("tableFooters", footerRowRightCellStyle);

    CellStyle bodyRowLeftCellStyle = workbook.createCellStyle();
    bodyRowLeftCellStyle.cloneStyleFrom(style);
    Font titleBodyFont = workbook.createFont();
    titleBodyFont.setFontHeightInPoints((short) 14);
    titleBodyFont.setFontName("Calibri");
    bodyRowLeftCellStyle.setFont(titleBodyFont);
    bodyRowLeftCellStyle.setBorderTop(CellStyle.BORDER_THIN);
    bodyRowLeftCellStyle.setFillPattern(CellStyle.NO_FILL);

    styles.put("tableBodyLeft", bodyRowLeftCellStyle);

    CellStyle bodyRowMiddleCellStyle = workbook.createCellStyle();
    bodyRowMiddleCellStyle.cloneStyleFrom(bodyRowLeftCellStyle);
    bodyRowMiddleCellStyle.setBorderLeft(CellStyle.BORDER_THIN);

    styles.put("tableBodyMiddle", bodyRowMiddleCellStyle);

    CellStyle bodyRowRightCellStyle = workbook.createCellStyle();
    bodyRowRightCellStyle.cloneStyleFrom(bodyRowMiddleCellStyle);
    bodyRowRightCellStyle.setBorderRight(CellStyle.BORDER_MEDIUM);

    styles.put("tableBodyRight", bodyRowRightCellStyle);

    return styles;
}

From source file:com.griffinslogistics.document.excel.CMRGenerator.java

private static Map<String, CellStyle> createStyles(Workbook workbook) {
    Map<String, CellStyle> styles = new HashMap<String, CellStyle>();

    CellStyle style = workbook.createCellStyle();
    Font font = workbook.createFont();
    font.setBoldweight(Font.BOLDWEIGHT_BOLD);
    styles.put(DEFAULT_STYLE, style);// w ww .  j ava  2  s  .c om

    CellStyle labelStyle = workbook.createCellStyle();
    font = workbook.createFont();
    font.setFontHeightInPoints((short) 10);
    font.setColor(HSSFColor.DARK_RED.index);
    labelStyle.setFont(font);
    labelStyle.setWrapText(true);
    styles.put(LABEL_STYLE, labelStyle);

    CellStyle labelTopStyle = workbook.createCellStyle();
    labelTopStyle.cloneStyleFrom(labelStyle);
    labelTopStyle.setBorderLeft(CellStyle.BORDER_MEDIUM);
    labelTopStyle.setBorderTop(CellStyle.BORDER_MEDIUM);
    labelTopStyle.setBorderRight(CellStyle.BORDER_MEDIUM);
    labelTopStyle.setVerticalAlignment(CellStyle.VERTICAL_TOP);
    styles.put(LABEL_TOP_STYLE, labelTopStyle);

    CellStyle labelMiddleStyle = workbook.createCellStyle();
    labelMiddleStyle.cloneStyleFrom(labelStyle);
    labelMiddleStyle.setBorderLeft(CellStyle.BORDER_MEDIUM);
    labelMiddleStyle.setBorderRight(CellStyle.BORDER_MEDIUM);
    labelMiddleStyle.setVerticalAlignment(CellStyle.VERTICAL_TOP);
    styles.put(LABEL_MIDDLE_STYLE, labelMiddleStyle);

    CellStyle labelLeftStyle = workbook.createCellStyle();
    labelLeftStyle.cloneStyleFrom(labelStyle);
    labelLeftStyle.setBorderLeft(CellStyle.BORDER_MEDIUM);
    labelLeftStyle.setVerticalAlignment(CellStyle.VERTICAL_TOP);
    styles.put(LABEL_LEFT_STYLE, labelLeftStyle);

    CellStyle labelRightStyle = workbook.createCellStyle();
    labelRightStyle.cloneStyleFrom(labelStyle);
    labelRightStyle.setBorderRight(CellStyle.BORDER_MEDIUM);
    labelRightStyle.setVerticalAlignment(CellStyle.VERTICAL_TOP);
    styles.put(LABEL_RIGHT_STYLE, labelRightStyle);

    CellStyle labelBottomStyle = workbook.createCellStyle();
    labelBottomStyle.cloneStyleFrom(labelStyle);
    labelBottomStyle.setBorderLeft(CellStyle.BORDER_MEDIUM);
    labelBottomStyle.setBorderRight(CellStyle.BORDER_MEDIUM);
    labelBottomStyle.setBorderBottom(CellStyle.BORDER_MEDIUM);
    styles.put(LABEL_BOTTOM_STYLE, labelBottomStyle);

    CellStyle labelWholeStyle = workbook.createCellStyle();
    labelWholeStyle.cloneStyleFrom(labelStyle);
    labelWholeStyle.setBorderLeft(CellStyle.BORDER_MEDIUM);
    labelWholeStyle.setBorderRight(CellStyle.BORDER_MEDIUM);
    labelWholeStyle.setBorderBottom(CellStyle.BORDER_MEDIUM);
    labelWholeStyle.setBorderTop(CellStyle.BORDER_MEDIUM);
    labelWholeStyle.setVerticalAlignment(CellStyle.VERTICAL_TOP);
    styles.put(LABEL_WHOLE_STYLE, labelWholeStyle);

    Font contentFont = workbook.createFont();
    contentFont.setFontHeightInPoints((short) 12);
    contentFont.setBoldweight(Font.BOLDWEIGHT_BOLD);

    CellStyle contentTopStyle = workbook.createCellStyle();
    contentTopStyle.cloneStyleFrom(labelTopStyle);
    contentTopStyle.setFont(contentFont);
    styles.put(CONTENT_TOP_STYLE, contentTopStyle);

    CellStyle contentMiddleStyle = workbook.createCellStyle();
    contentMiddleStyle.cloneStyleFrom(labelMiddleStyle);
    contentMiddleStyle.setFont(contentFont);
    styles.put(CONTENT_MIDDLE_STYLE, contentMiddleStyle);

    CellStyle contentMiddleAllignRightStyle = workbook.createCellStyle();
    contentMiddleAllignRightStyle.cloneStyleFrom(contentMiddleStyle);
    contentMiddleAllignRightStyle.setBorderRight(CellStyle.BORDER_NONE);
    contentMiddleAllignRightStyle.setFont(contentFont);
    contentMiddleAllignRightStyle.setAlignment(CellStyle.ALIGN_RIGHT);
    styles.put(CONTENT_MIDDLE_ALLIGN_RIGHT_STYLE, contentMiddleAllignRightStyle);

    CellStyle contentBottomAllignCenterStyle = workbook.createCellStyle();
    contentBottomAllignCenterStyle.cloneStyleFrom(contentMiddleStyle);
    contentBottomAllignCenterStyle.setBorderRight(CellStyle.BORDER_MEDIUM);
    contentBottomAllignCenterStyle.setBorderBottom(CellStyle.BORDER_MEDIUM);
    contentBottomAllignCenterStyle.setFont(contentFont);
    contentBottomAllignCenterStyle.setAlignment(CellStyle.ALIGN_CENTER);
    styles.put(CONTENT_BOTTOM_ALLIGN_CENTER_STYLE, contentBottomAllignCenterStyle);

    CellStyle contentMiddleNoBordersAllignRightStyle = workbook.createCellStyle();
    contentMiddleNoBordersAllignRightStyle.cloneStyleFrom(contentMiddleAllignRightStyle);
    contentMiddleNoBordersAllignRightStyle.setBorderLeft(CellStyle.BORDER_NONE);
    contentMiddleNoBordersAllignRightStyle.setAlignment(CellStyle.ALIGN_CENTER);
    contentMiddleNoBordersAllignRightStyle.setFont(contentFont);
    styles.put(CONTENT_MIDDLE_NO_BORDERS_STYLE, contentMiddleNoBordersAllignRightStyle);

    CellStyle contentMiddleAllignCenterStyle = workbook.createCellStyle();
    contentMiddleAllignCenterStyle.cloneStyleFrom(contentMiddleStyle);
    contentMiddleAllignCenterStyle.setAlignment(CellStyle.ALIGN_CENTER);
    contentMiddleAllignCenterStyle.setFont(contentFont);
    styles.put(CONTENT_MIDDLE_ALLIGN_CENTER_STYLE, contentMiddleAllignCenterStyle);

    CellStyle contentRightStyle = workbook.createCellStyle();
    contentRightStyle.cloneStyleFrom(labelRightStyle);
    contentRightStyle.setFont(contentFont);
    styles.put(CONTENT_RIGHT_STYLE, contentRightStyle);

    CellStyle contentBottomStyle = workbook.createCellStyle();
    contentBottomStyle.cloneStyleFrom(labelBottomStyle);
    contentBottomStyle.setFont(contentFont);
    styles.put(CONTENT_BOTTOM_STYLE, contentBottomStyle);

    CellStyle contentWholeStyle = workbook.createCellStyle();
    contentWholeStyle.cloneStyleFrom(labelWholeStyle);
    contentWholeStyle.setFont(contentFont);
    styles.put(CONTENT_WHOLE_STYLE, contentWholeStyle);

    return styles;
}