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

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

Introduction

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

Prototype

HorizontalAlignment CENTER

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

Click Source Link

Document

The horizontal alignment is centered, meaning the text is centered across the cell.

Usage

From source file:com.netsteadfast.greenstep.bsc.command.KpisDashboardExcelCommand.java

License:Apache License

@SuppressWarnings("unchecked")
private int putTables(XSSFWorkbook wb, XSSFSheet sh, Context context) throws Exception {

    XSSFCellStyle cellHeadStyle = wb.createCellStyle();
    cellHeadStyle.setFillForegroundColor(new XSSFColor(SimpleUtils.getColorRGB4POIColor("#f5f5f5")));
    cellHeadStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
    cellHeadStyle.setBorderBottom(BorderStyle.THIN);
    cellHeadStyle.setBorderTop(BorderStyle.THIN);
    cellHeadStyle.setBorderRight(BorderStyle.THIN);
    cellHeadStyle.setBorderLeft(BorderStyle.THIN);
    XSSFFont cellHeadFont = wb.createFont();
    cellHeadFont.setBold(true);//from w w  w.  j  a v  a2  s . co  m
    cellHeadStyle.setFont(cellHeadFont);

    sh.setColumnWidth(0, 12000);

    int left = 0;
    int row = 0;
    List<Map<String, Object>> chartDatas = (List<Map<String, Object>>) context.get("chartDatas");
    for (Map<String, Object> data : chartDatas) {
        Row nowRow = sh.createRow(row);
        Map<String, Object> nodeData = (Map<String, Object>) ((List<Object>) data.get("datas")).get(0);

        if (row == 0) {
            Cell cell1 = nowRow.createCell(0);
            cell1.setCellStyle(cellHeadStyle);
            cell1.setCellValue("KPI");
            Cell cell2 = nowRow.createCell(1);
            cell2.setCellStyle(cellHeadStyle);
            cell2.setCellValue("Maximum");
            Cell cell3 = nowRow.createCell(2);
            cell3.setCellStyle(cellHeadStyle);
            cell3.setCellValue("Target");
            Cell cell4 = nowRow.createCell(3);
            cell4.setCellStyle(cellHeadStyle);
            cell4.setCellValue("Minimum");
            Cell cell5 = nowRow.createCell(4);
            cell5.setCellStyle(cellHeadStyle);
            cell5.setCellValue("Score");

            List<Map<String, Object>> dateRangeScores = (List<Map<String, Object>>) nodeData
                    .get("dateRangeScores");
            for (Map<String, Object> rangeScore : dateRangeScores) {
                Cell cell = nowRow.createCell(5 + left);
                cell.setCellStyle(cellHeadStyle);
                cell.setCellValue(String.valueOf(rangeScore.get("date")));
                left++;
            }

            row++;
        }

        left = 0;
        nowRow = sh.createRow(row);

        XSSFColor bgColor = new XSSFColor(SimpleUtils.getColorRGB4POIColor((String) nodeData.get("bgColor")));
        XSSFColor fnColor = new XSSFColor(SimpleUtils.getColorRGB4POIColor((String) nodeData.get("fontColor")));
        XSSFCellStyle cellStyle = wb.createCellStyle();
        cellStyle.setFillForegroundColor(bgColor);
        cellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
        XSSFFont cellFont = wb.createFont();
        cellFont.setBold(false);
        cellFont.setColor(fnColor);
        cellStyle.setFont(cellFont);
        cellStyle.setWrapText(true);
        cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
        cellStyle.setAlignment(HorizontalAlignment.CENTER);
        cellStyle.setBorderBottom(BorderStyle.THIN);
        cellStyle.setBorderTop(BorderStyle.THIN);
        cellStyle.setBorderRight(BorderStyle.THIN);
        cellStyle.setBorderLeft(BorderStyle.THIN);

        Cell cell1 = nowRow.createCell(0);
        cell1.setCellValue(String.valueOf(nodeData.get("name")));
        Cell cell2 = nowRow.createCell(1);
        cell2.setCellValue(String.valueOf(nodeData.get("max")));
        Cell cell3 = nowRow.createCell(2);
        cell3.setCellValue(String.valueOf(nodeData.get("target")));
        Cell cell4 = nowRow.createCell(3);
        cell4.setCellValue(String.valueOf(nodeData.get("min")));
        Cell cell5 = nowRow.createCell(4);
        cell5.setCellValue(String.valueOf(nodeData.get("score")));
        cell5.setCellStyle(cellStyle);

        List<Map<String, Object>> dateRangeScores = (List<Map<String, Object>>) nodeData.get("dateRangeScores");
        for (Map<String, Object> rangeScore : dateRangeScores) {
            bgColor = new XSSFColor(SimpleUtils.getColorRGB4POIColor((String) rangeScore.get("bgColor")));
            fnColor = new XSSFColor(SimpleUtils.getColorRGB4POIColor((String) rangeScore.get("fontColor")));
            cellStyle = wb.createCellStyle();
            cellStyle.setFillForegroundColor(bgColor);
            cellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
            cellFont = wb.createFont();
            cellFont.setBold(false);
            cellFont.setColor(fnColor);
            cellStyle.setFont(cellFont);
            cellStyle.setWrapText(true);
            cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
            cellStyle.setAlignment(HorizontalAlignment.CENTER);
            cellStyle.setBorderBottom(BorderStyle.THIN);
            cellStyle.setBorderTop(BorderStyle.THIN);
            cellStyle.setBorderRight(BorderStyle.THIN);
            cellStyle.setBorderLeft(BorderStyle.THIN);

            Cell cell = nowRow.createCell(5 + left);
            cell.setCellStyle(cellHeadStyle);
            cell.setCellValue(String.valueOf(rangeScore.get("score")));
            cell.setCellStyle(cellStyle);

            left++;
        }

        row++;
    }
    return row + 1;
}

From source file:com.netsteadfast.greenstep.bsc.command.OrganizationReportExcelCommand.java

License:Apache License

private int createHead(XSSFWorkbook wb, XSSFSheet sh, int row, VisionVO vision, Context context)
        throws Exception {
    String dateType = (String) context.get("dateType");
    String year = (String) context.get("startYearDate");
    String orgId = (String) context.get("orgId");
    String departmentName = "";
    String dateTypeName = "Year";
    if ("1".equals(dateType)) {
        dateTypeName = "In the first half";
    }/*from   w  ww.j  a v  a2  s.c o  m*/
    if ("2".equals(dateType)) {
        dateTypeName = "In the second half";
    }
    OrganizationVO organization = new OrganizationVO();
    organization.setOrgId(orgId);
    DefaultResult<OrganizationVO> result = this.organizationService.findByUK(organization);
    if (result.getValue() != null) {
        organization = result.getValue();
        departmentName = organization.getName();
    }

    Row headRow = sh.createRow(row);
    headRow.setHeight((short) 700);

    XSSFColor bgColor = new XSSFColor(SimpleUtils.getColorRGB4POIColor("#F2F2F2"));
    XSSFColor fnColor = new XSSFColor(SimpleUtils.getColorRGB4POIColor("#000000"));

    XSSFCellStyle cellHeadStyle = wb.createCellStyle();
    cellHeadStyle.setFillForegroundColor(bgColor);
    cellHeadStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);

    XSSFFont cellHeadFont = wb.createFont();
    cellHeadFont.setBold(true);
    cellHeadFont.setColor(fnColor);
    cellHeadStyle.setFont(cellHeadFont);
    cellHeadStyle.setBorderBottom(BorderStyle.THIN);
    cellHeadStyle.setBorderTop(BorderStyle.THIN);
    cellHeadStyle.setBorderRight(BorderStyle.THIN);
    cellHeadStyle.setBorderLeft(BorderStyle.THIN);
    cellHeadStyle.setVerticalAlignment(VerticalAlignment.CENTER);
    cellHeadStyle.setAlignment(HorizontalAlignment.CENTER);
    cellHeadStyle.setWrapText(true);

    int cols = 6;
    for (int i = 0; i < cols; i++) {
        sh.setColumnWidth(i, 6000);
        Cell headCell1 = headRow.createCell(i);
        headCell1.setCellValue("Personal Balance SourceCard");
        headCell1.setCellStyle(cellHeadStyle);
    }
    sh.addMergedRegion(new CellRangeAddress(row, row, 0, cols - 1));

    row++;
    headRow = sh.createRow(row);
    for (int i = 0; i < cols; i++) {
        sh.setColumnWidth(i, 6000);
        Cell headCell1 = headRow.createCell(i);
        headCell1.setCellValue(vision.getTitle());
        headCell1.setCellStyle(cellHeadStyle);
    }
    sh.addMergedRegion(new CellRangeAddress(row, row, 0, cols - 1));

    row++;
    headRow = sh.createRow(row);

    Cell titleCell1 = headRow.createCell(0);
    titleCell1.setCellValue("Department");
    titleCell1.setCellStyle(cellHeadStyle);

    Cell titleCell2 = headRow.createCell(1);
    titleCell2.setCellValue(departmentName);
    titleCell2.setCellStyle(cellHeadStyle);

    Cell titleCell3 = headRow.createCell(2);
    titleCell3.setCellValue(departmentName);
    titleCell3.setCellStyle(cellHeadStyle);

    Cell titleCell4 = headRow.createCell(3);
    titleCell4.setCellValue(departmentName);
    titleCell4.setCellStyle(cellHeadStyle);

    Cell titleCell5 = headRow.createCell(4);
    titleCell5.setCellValue(departmentName);
    titleCell5.setCellStyle(cellHeadStyle);

    Cell titleCell6 = headRow.createCell(5);
    titleCell6.setCellValue(year + " " + dateTypeName);
    titleCell6.setCellStyle(cellHeadStyle);

    sh.addMergedRegion(new CellRangeAddress(row, row, 1, cols - 2));

    row++;
    headRow = sh.createRow(row);

    titleCell1 = headRow.createCell(0);
    titleCell1.setCellValue(BscReportPropertyUtils.getPerspectiveTitle());
    titleCell1.setCellStyle(cellHeadStyle);

    titleCell2 = headRow.createCell(1);
    titleCell2.setCellValue(BscReportPropertyUtils.getObjectiveTitle());
    titleCell2.setCellStyle(cellHeadStyle);

    titleCell3 = headRow.createCell(2);
    titleCell3.setCellValue(BscReportPropertyUtils.getKpiTitle());
    titleCell3.setCellStyle(cellHeadStyle);

    titleCell4 = headRow.createCell(3);
    titleCell4.setCellValue("Weight");
    titleCell4.setCellStyle(cellHeadStyle);

    titleCell5 = headRow.createCell(4);
    titleCell5.setCellValue("Maximum\nTarget\nMinimum");
    titleCell5.setCellStyle(cellHeadStyle);

    titleCell6 = headRow.createCell(5);
    titleCell6.setCellValue("Score");
    titleCell6.setCellStyle(cellHeadStyle);

    row = row + 1;
    return row;
}

From source file:com.netsteadfast.greenstep.bsc.command.PdcaReportExcelCommand.java

License:Apache License

private int createPdca(XSSFWorkbook wb, XSSFSheet sh, int row, Context context) throws Exception {

    PdcaVO pdca = (PdcaVO) this.getResult(context);

    Row headRow = sh.createRow(row);/*from   ww  w . j  ava  2 s  .c  o  m*/
    headRow.setHeight((short) 700);

    // --------------------------------------------------------------------------------------

    XSSFColor bgColor = new XSSFColor(SimpleUtils.getColorRGB4POIColor("#d8d8d8"));
    XSSFColor fnColor = new XSSFColor(SimpleUtils.getColorRGB4POIColor("#000000"));

    XSSFCellStyle cellHeadStyle = wb.createCellStyle();
    cellHeadStyle.setFillForegroundColor(bgColor);
    cellHeadStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);

    XSSFFont cellHeadFont = wb.createFont();
    cellHeadFont.setBold(true);
    cellHeadFont.setColor(fnColor);
    cellHeadStyle.setFont(cellHeadFont);
    cellHeadStyle.setBorderBottom(BorderStyle.THIN);
    cellHeadStyle.setBorderTop(BorderStyle.THIN);
    cellHeadStyle.setBorderRight(BorderStyle.THIN);
    cellHeadStyle.setBorderLeft(BorderStyle.THIN);
    cellHeadStyle.setVerticalAlignment(VerticalAlignment.CENTER);
    cellHeadStyle.setAlignment(HorizontalAlignment.CENTER);
    cellHeadStyle.setWrapText(true);

    // --------------------------------------------------------------------------------------

    int cols = 6;
    for (int i = 0; i < cols; i++) {
        sh.setColumnWidth(i, 6000);
        Cell headCell1 = headRow.createCell(i);
        headCell1.setCellValue(pdca.getTitle());
        headCell1.setCellStyle(cellHeadStyle);
    }
    sh.addMergedRegion(new CellRangeAddress(row, row, 0, cols - 1));

    // --------------------------------------------------------------------------------------

    XSSFColor bgLabelColor = new XSSFColor(SimpleUtils.getColorRGB4POIColor("#F2F2F2"));

    XSSFCellStyle cellLabelStyle = wb.createCellStyle();
    cellLabelStyle.setFillForegroundColor(bgLabelColor);
    cellLabelStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);

    XSSFFont cellLabelFont = wb.createFont();
    cellLabelFont.setBold(true);
    cellLabelFont.setColor(fnColor);
    cellLabelStyle.setFont(cellLabelFont);
    cellLabelStyle.setBorderBottom(BorderStyle.THIN);
    cellLabelStyle.setBorderTop(BorderStyle.THIN);
    cellLabelStyle.setBorderRight(BorderStyle.THIN);
    cellLabelStyle.setBorderLeft(BorderStyle.THIN);
    cellLabelStyle.setVerticalAlignment(VerticalAlignment.CENTER);
    cellLabelStyle.setAlignment(HorizontalAlignment.LEFT);
    cellLabelStyle.setWrapText(true);

    // --------------------------------------------------------------------------------------

    XSSFColor bgNormalColor = new XSSFColor(SimpleUtils.getColorRGB4POIColor("#ffffff"));

    XSSFCellStyle cellNormalStyle = wb.createCellStyle();
    cellNormalStyle.setFillForegroundColor(bgNormalColor);
    cellNormalStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);

    XSSFFont cellNormalFont = wb.createFont();
    cellNormalFont.setBold(false);
    cellNormalFont.setColor(fnColor);
    cellNormalStyle.setFont(cellNormalFont);
    cellNormalStyle.setBorderBottom(BorderStyle.THIN);
    cellNormalStyle.setBorderTop(BorderStyle.THIN);
    cellNormalStyle.setBorderRight(BorderStyle.THIN);
    cellNormalStyle.setBorderLeft(BorderStyle.THIN);
    cellNormalStyle.setVerticalAlignment(VerticalAlignment.CENTER);
    cellNormalStyle.setAlignment(HorizontalAlignment.LEFT);
    cellNormalStyle.setWrapText(true);

    // --------------------------------------------------------------------------------------

    row++;

    Row labelRow = sh.createRow(row);
    Cell labelCell_0_1 = labelRow.createCell(0);
    labelCell_0_1.setCellValue("Responsibility");
    labelCell_0_1.setCellStyle(cellLabelStyle);

    Cell labelCell_0_2 = labelRow.createCell(1);
    labelCell_0_2.setCellValue(pdca.getResponsibilityAppendNames());
    labelCell_0_2.setCellStyle(cellNormalStyle);

    Cell labelCell_0_3 = labelRow.createCell(2);
    labelCell_0_3.setCellValue(pdca.getResponsibilityAppendNames());
    labelCell_0_3.setCellStyle(cellNormalStyle);

    sh.addMergedRegion(new CellRangeAddress(row, row, 1, 2));

    Cell labelCell_0_4 = labelRow.createCell(3);
    labelCell_0_4.setCellValue("Date range");
    labelCell_0_4.setCellStyle(cellLabelStyle);

    Cell labelCell_0_5 = labelRow.createCell(4);
    labelCell_0_5.setCellValue(pdca.getStartDateDisplayValue() + " ~ " + pdca.getEndDateDisplayValue());
    labelCell_0_5.setCellStyle(cellNormalStyle);

    Cell labelCell_0_6 = labelRow.createCell(5);
    labelCell_0_6.setCellValue(pdca.getStartDateDisplayValue() + " ~ " + pdca.getEndDateDisplayValue());
    labelCell_0_6.setCellStyle(cellNormalStyle);

    sh.addMergedRegion(new CellRangeAddress(row, row, 4, 5));

    // --------------------------------------------------------------------------------------

    row++;

    labelRow = sh.createRow(row);
    Cell labelCell_1_1 = labelRow.createCell(0);
    labelCell_1_1.setCellValue("Confirm");
    labelCell_1_1.setCellStyle(cellLabelStyle);

    Cell labelCell_1_2 = labelRow.createCell(1);
    labelCell_1_2.setCellValue(pdca.getConfirmEmployeeName());
    labelCell_1_2.setCellStyle(cellNormalStyle);

    Cell labelCell_1_3 = labelRow.createCell(2);
    labelCell_1_3.setCellValue(pdca.getConfirmEmployeeName());
    labelCell_1_3.setCellStyle(cellNormalStyle);

    sh.addMergedRegion(new CellRangeAddress(row, row, 1, 2));

    Cell labelCell_1_4 = labelRow.createCell(3);
    labelCell_1_4.setCellValue("Confirm date");
    labelCell_1_4.setCellStyle(cellLabelStyle);

    Cell labelCell_1_5 = labelRow.createCell(4);
    labelCell_1_5.setCellValue(pdca.getConfirmDateDisplayValue());
    labelCell_1_5.setCellStyle(cellNormalStyle);

    Cell labelCell_1_6 = labelRow.createCell(5);
    labelCell_1_6.setCellValue(pdca.getConfirmDateDisplayValue());
    labelCell_1_6.setCellStyle(cellNormalStyle);

    sh.addMergedRegion(new CellRangeAddress(row, row, 4, 5));

    // --------------------------------------------------------------------------------------

    row++;

    labelRow = sh.createRow(row);
    Cell labelCell_2_1 = labelRow.createCell(0);
    labelCell_2_1.setCellValue("Organization\nDepartment");
    labelCell_2_1.setCellStyle(cellLabelStyle);

    Cell labelCell_2_2 = labelRow.createCell(1);
    labelCell_2_2.setCellValue(pdca.getOrganizationAppendNames());
    labelCell_2_2.setCellStyle(cellNormalStyle);

    Cell labelCell_2_3 = labelRow.createCell(2);
    labelCell_2_3.setCellValue(pdca.getOrganizationAppendNames());
    labelCell_2_3.setCellStyle(cellNormalStyle);

    Cell labelCell_2_4 = labelRow.createCell(3);
    labelCell_2_4.setCellValue(pdca.getOrganizationAppendNames());
    labelCell_2_4.setCellStyle(cellNormalStyle);

    Cell labelCell_2_5 = labelRow.createCell(4);
    labelCell_2_5.setCellValue(pdca.getOrganizationAppendNames());
    labelCell_2_5.setCellStyle(cellNormalStyle);

    Cell labelCell_2_6 = labelRow.createCell(5);
    labelCell_2_6.setCellValue(pdca.getOrganizationAppendNames());
    labelCell_2_6.setCellStyle(cellNormalStyle);

    sh.addMergedRegion(new CellRangeAddress(row, row, 1, 5));

    // --------------------------------------------------------------------------------------

    row++;

    labelRow = sh.createRow(row);
    Cell labelCell_3_1 = labelRow.createCell(0);
    labelCell_3_1.setCellValue("KPIs");
    labelCell_3_1.setCellStyle(cellLabelStyle);

    Cell labelCell_3_2 = labelRow.createCell(1);
    labelCell_3_2.setCellValue(pdca.getKpisAppendNames());
    labelCell_3_2.setCellStyle(cellNormalStyle);

    Cell labelCell_3_3 = labelRow.createCell(2);
    labelCell_3_3.setCellValue(pdca.getKpisAppendNames());
    labelCell_3_3.setCellStyle(cellNormalStyle);

    Cell labelCell_3_4 = labelRow.createCell(3);
    labelCell_3_4.setCellValue(pdca.getKpisAppendNames());
    labelCell_3_4.setCellStyle(cellNormalStyle);

    Cell labelCell_3_5 = labelRow.createCell(4);
    labelCell_3_5.setCellValue(pdca.getKpisAppendNames());
    labelCell_3_5.setCellStyle(cellNormalStyle);

    Cell labelCell_3_6 = labelRow.createCell(5);
    labelCell_3_6.setCellValue(pdca.getKpisAppendNames());
    labelCell_3_6.setCellStyle(cellNormalStyle);

    sh.addMergedRegion(new CellRangeAddress(row, row, 1, 5));

    // --------------------------------------------------------------------------------------

    row++;

    labelRow = sh.createRow(row);
    Cell labelCell_4_1 = labelRow.createCell(0);
    labelCell_4_1.setCellValue("Parent PDCA");
    labelCell_4_1.setCellStyle(cellLabelStyle);

    Cell labelCell_4_2 = labelRow.createCell(1);
    labelCell_4_2.setCellValue(pdca.getParentName());
    labelCell_4_2.setCellStyle(cellNormalStyle);

    Cell labelCell_4_3 = labelRow.createCell(2);
    labelCell_4_3.setCellValue(pdca.getParentName());
    labelCell_4_3.setCellStyle(cellNormalStyle);

    Cell labelCell_4_4 = labelRow.createCell(3);
    labelCell_4_4.setCellValue(pdca.getParentName());
    labelCell_4_4.setCellStyle(cellNormalStyle);

    Cell labelCell_4_5 = labelRow.createCell(4);
    labelCell_4_5.setCellValue(pdca.getParentName());
    labelCell_4_5.setCellStyle(cellNormalStyle);

    Cell labelCell_4_6 = labelRow.createCell(5);
    labelCell_4_6.setCellValue(pdca.getParentName());
    labelCell_4_6.setCellStyle(cellNormalStyle);

    sh.addMergedRegion(new CellRangeAddress(row, row, 1, 5));

    // --------------------------------------------------------------------------------------

    row++;

    labelRow = sh.createRow(row);
    Cell labelCell_6_1 = labelRow.createCell(0);
    labelCell_6_1.setCellValue("TYPE");
    labelCell_6_1.setCellStyle(cellLabelStyle);

    Cell labelCell_6_2 = labelRow.createCell(1);
    labelCell_6_2.setCellValue("Title");
    labelCell_6_2.setCellStyle(cellLabelStyle);

    Cell labelCell_6_3 = labelRow.createCell(2);
    labelCell_6_3.setCellValue("Responsibility");
    labelCell_6_3.setCellStyle(cellLabelStyle);

    Cell labelCell_6_4 = labelRow.createCell(3);
    labelCell_6_4.setCellValue("Date range");
    labelCell_6_4.setCellStyle(cellLabelStyle);

    Cell labelCell_6_5 = labelRow.createCell(4);
    labelCell_6_5.setCellValue("Audit");
    labelCell_6_5.setCellStyle(cellLabelStyle);

    Cell labelCell_6_6 = labelRow.createCell(5);
    labelCell_6_6.setCellValue("Audit date");
    labelCell_6_6.setCellStyle(cellLabelStyle);

    // --------------------------------------------------------------------------------------

    row++;

    int nRow = row;

    row = this.createPdcaItem(wb, sh, row, cellNormalStyle, pdca.getItemPlan(), pdca.getAuditPlan());
    row = this.createPdcaItem(wb, sh, row, cellNormalStyle, pdca.getItemDo(), pdca.getAuditDo());
    row = this.createPdcaItem(wb, sh, row, cellNormalStyle, pdca.getItemCheck(), pdca.getAuditCheck());
    row = this.createPdcaItem(wb, sh, row, cellNormalStyle, pdca.getItemAction(), pdca.getAuditAction());

    nRow = this.mergedRegionForItemsRow(wb, sh, nRow, pdca.getItemPlan());
    nRow = this.mergedRegionForItemsRow(wb, sh, nRow, pdca.getItemDo());
    nRow = this.mergedRegionForItemsRow(wb, sh, nRow, pdca.getItemCheck());
    nRow = this.mergedRegionForItemsRow(wb, sh, nRow, pdca.getItemAction());

    return row;
}

From source file:com.netsteadfast.greenstep.bsc.command.PdcaReportExcelCommand.java

License:Apache License

private int createPdcaItem(XSSFWorkbook wb, XSSFSheet sh, int row, XSSFCellStyle cellNormalStyle,
        List<PdcaItemVO> items, PdcaAuditVO audit) throws Exception {

    XSSFColor fnColor = new XSSFColor(SimpleUtils.getColorRGB4POIColor("#000000"));
    XSSFColor bgLabelColor = new XSSFColor(SimpleUtils.getColorRGB4POIColor("#F2F2F2"));

    XSSFCellStyle cellLabelStyle = wb.createCellStyle();
    cellLabelStyle.setFillForegroundColor(bgLabelColor);
    cellLabelStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);

    XSSFFont cellLabelFont = wb.createFont();
    cellLabelFont.setBold(true);//from www .java  2  s. com
    cellLabelFont.setColor(fnColor);
    cellLabelStyle.setFont(cellLabelFont);
    cellLabelStyle.setBorderBottom(BorderStyle.THIN);
    cellLabelStyle.setBorderTop(BorderStyle.THIN);
    cellLabelStyle.setBorderRight(BorderStyle.THIN);
    cellLabelStyle.setBorderLeft(BorderStyle.THIN);
    cellLabelStyle.setVerticalAlignment(VerticalAlignment.CENTER);
    cellLabelStyle.setAlignment(HorizontalAlignment.CENTER);
    cellLabelStyle.setWrapText(true);

    Map<String, String> pdcaTypeMap = PdcaType.getDataMap(false);

    for (PdcaItemVO item : items) {

        Row labelRow = sh.createRow(row);
        Cell labelCell_6_1 = labelRow.createCell(0);
        labelCell_6_1.setCellValue(pdcaTypeMap.get(item.getType()));
        labelCell_6_1.setCellStyle(cellLabelStyle);

        Cell labelCell_6_2 = labelRow.createCell(1);
        labelCell_6_2.setCellValue(item.getTitle()
                + (!StringUtils.isBlank(item.getDescription()) ? "\n\n" + item.getDescription() : ""));
        labelCell_6_2.setCellStyle(cellNormalStyle);

        Cell labelCell_6_3 = labelRow.createCell(2);
        labelCell_6_3.setCellValue(item.getEmployeeAppendNames());
        labelCell_6_3.setCellStyle(cellNormalStyle);

        Cell labelCell_6_4 = labelRow.createCell(3);
        labelCell_6_4.setCellValue(item.getStartDateDisplayValue() + " ~ " + item.getEndDateDisplayValue());
        labelCell_6_4.setCellStyle(cellNormalStyle);

        Cell labelCell_6_5 = labelRow.createCell(4);
        labelCell_6_5.setCellValue((audit != null ? audit.getEmpId() : " "));
        labelCell_6_5.setCellStyle(cellNormalStyle);

        Cell labelCell_6_6 = labelRow.createCell(5);
        labelCell_6_6.setCellValue((audit != null ? audit.getConfirmDateDisplayValue() : " "));
        labelCell_6_6.setCellStyle(cellNormalStyle);

        row++;

    }

    return row;
}

From source file:com.netsteadfast.greenstep.bsc.command.PersonalReportExcelCommand.java

License:Apache License

private int createHead(XSSFWorkbook wb, XSSFSheet sh, int row, VisionVO vision, Context context)
        throws Exception {
    String dateType = (String) context.get("dateType");
    String year = (String) context.get("startYearDate");
    String empId = (String) context.get("empId");
    String account = (String) context.get("account");
    String fullName = "";
    String jobTitle = "";
    String departmentName = "";
    String dateTypeName = "Year";
    if ("1".equals(dateType)) {
        dateTypeName = "In the first half";
    }//from  w w  w.  j  ava 2s  .c om
    if ("2".equals(dateType)) {
        dateTypeName = "In the second half";
    }
    EmployeeVO employee = new EmployeeVO();
    employee.setEmpId(empId);
    employee.setAccount(account);
    DefaultResult<EmployeeVO> result = this.employeeService.findByUK(employee);
    if (result.getValue() != null) {
        fullName = result.getValue().getEmpId() + " - " + result.getValue().getFullName();
        jobTitle = result.getValue().getEmpId() + " - " + result.getValue().getFullName();
        List<String> appendIds = this.organizationService
                .findForAppendOrganizationOids(result.getValue().getEmpId());
        List<String> appendNames = this.organizationService.findForAppendNames(appendIds);
        StringBuilder sb = new StringBuilder();
        for (int i = 0; appendNames != null && i < appendNames.size(); i++) {
            sb.append(appendNames.get(i)).append(Constants.ID_DELIMITER);
        }
        departmentName = sb.toString();
    }

    Row headRow = sh.createRow(row);
    headRow.setHeight((short) 700);

    XSSFColor bgColor = new XSSFColor(SimpleUtils.getColorRGB4POIColor("#F2F2F2"));
    XSSFColor fnColor = new XSSFColor(SimpleUtils.getColorRGB4POIColor("#000000"));

    XSSFCellStyle cellHeadStyle = wb.createCellStyle();
    cellHeadStyle.setFillForegroundColor(bgColor);
    cellHeadStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);

    XSSFFont cellHeadFont = wb.createFont();
    cellHeadFont.setBold(true);
    cellHeadFont.setColor(fnColor);
    cellHeadStyle.setFont(cellHeadFont);
    cellHeadStyle.setBorderBottom(BorderStyle.THIN);
    cellHeadStyle.setBorderTop(BorderStyle.THIN);
    cellHeadStyle.setBorderRight(BorderStyle.THIN);
    cellHeadStyle.setBorderLeft(BorderStyle.THIN);
    cellHeadStyle.setVerticalAlignment(VerticalAlignment.CENTER);
    cellHeadStyle.setAlignment(HorizontalAlignment.CENTER);
    cellHeadStyle.setWrapText(true);

    int cols = 6;
    for (int i = 0; i < cols; i++) {
        sh.setColumnWidth(i, 6000);
        Cell headCell1 = headRow.createCell(i);
        headCell1.setCellValue("Personal Balance SourceCard");
        headCell1.setCellStyle(cellHeadStyle);
    }
    sh.addMergedRegion(new CellRangeAddress(row, row, 0, cols - 1));

    row++;
    headRow = sh.createRow(row);
    for (int i = 0; i < cols; i++) {
        sh.setColumnWidth(i, 6000);
        Cell headCell1 = headRow.createCell(i);
        headCell1.setCellValue(vision.getTitle());
        headCell1.setCellStyle(cellHeadStyle);
    }
    sh.addMergedRegion(new CellRangeAddress(row, row, 0, cols - 1));

    row++;
    headRow = sh.createRow(row);
    headRow.setHeight((short) 700);

    Cell titleCell1 = headRow.createCell(0);
    titleCell1.setCellValue("Job Title");
    titleCell1.setCellStyle(cellHeadStyle);

    Cell titleCell2 = headRow.createCell(1);
    titleCell2.setCellValue(jobTitle);
    titleCell2.setCellStyle(cellHeadStyle);

    Cell titleCell3 = headRow.createCell(2);
    titleCell3.setCellValue("Department");
    titleCell3.setCellStyle(cellHeadStyle);

    Cell titleCell4 = headRow.createCell(3);
    titleCell4.setCellValue(departmentName);
    titleCell4.setCellStyle(cellHeadStyle);

    Cell titleCell5 = headRow.createCell(4);
    titleCell5.setCellValue("name: " + fullName);
    titleCell5.setCellStyle(cellHeadStyle);

    Cell titleCell6 = headRow.createCell(5);
    titleCell6.setCellValue("Annual assessment: " + year);
    titleCell6.setCellStyle(cellHeadStyle);

    row++;
    headRow = sh.createRow(row);

    titleCell1 = headRow.createCell(0);
    titleCell1.setCellValue(BscReportPropertyUtils.getObjectiveTitle());
    titleCell1.setCellStyle(cellHeadStyle);

    titleCell2 = headRow.createCell(1);
    titleCell2.setCellValue(BscReportPropertyUtils.getKpiTitle());
    titleCell2.setCellStyle(cellHeadStyle);

    titleCell3 = headRow.createCell(2);
    titleCell3.setCellValue("Maximum\nTarget\nMinimum");
    titleCell3.setCellStyle(cellHeadStyle);

    titleCell4 = headRow.createCell(3);
    titleCell4.setCellValue("Weight");
    titleCell4.setCellStyle(cellHeadStyle);

    titleCell5 = headRow.createCell(4);
    titleCell5.setCellValue("Formula");
    titleCell5.setCellStyle(cellHeadStyle);

    titleCell6 = headRow.createCell(5);
    titleCell6.setCellValue("Score");
    titleCell6.setCellStyle(cellHeadStyle);

    row++;
    headRow = sh.createRow(row);
    headRow.setHeight((short) 1000);

    titleCell1 = headRow.createCell(0);
    titleCell1.setCellValue("Objective of Strategy");
    titleCell1.setCellStyle(cellHeadStyle);

    titleCell2 = headRow.createCell(1);
    titleCell2.setCellValue("KPI");
    titleCell2.setCellStyle(cellHeadStyle);

    titleCell3 = headRow.createCell(2);
    titleCell3.setCellValue("Target");
    titleCell3.setCellStyle(cellHeadStyle);

    titleCell4 = headRow.createCell(3);
    titleCell4.setCellValue("Weight");
    titleCell4.setCellStyle(cellHeadStyle);

    titleCell5 = headRow.createCell(4);
    titleCell5.setCellValue("Formula");
    titleCell5.setCellStyle(cellHeadStyle);

    XSSFCellStyle titleStyle = wb.createCellStyle();
    titleStyle.setFillForegroundColor(bgColor);
    titleStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
    titleStyle.setFillForegroundColor(new XSSFColor(SimpleUtils.getColorRGB4POIColor("#F5F4F4")));
    titleStyle.setFont(cellHeadFont);
    titleStyle.setBorderBottom(BorderStyle.THIN);
    titleStyle.setBorderTop(BorderStyle.THIN);
    titleStyle.setBorderRight(BorderStyle.THIN);
    titleStyle.setBorderLeft(BorderStyle.THIN);
    titleStyle.setVerticalAlignment(VerticalAlignment.CENTER);
    titleStyle.setAlignment(HorizontalAlignment.CENTER);
    titleStyle.setWrapText(true);

    titleCell6 = headRow.createCell(5);
    titleCell6.setCellValue(dateTypeName);
    titleCell6.setCellStyle(titleStyle);

    for (int i = 0; i < 5; i++) {
        sh.addMergedRegion(new CellRangeAddress(row - 1, row, i, i));
    }

    return 5;
}

From source file:com.philips.his.pixiu.cdr.poi.BigGridDemo.java

License:Apache License

/**
 * Create a library of cell styles./*from w  w w  .  j a v a  2s  .  c om*/
 */
private static Map<String, XSSFCellStyle> createStyles(XSSFWorkbook wb) {
    Map<String, XSSFCellStyle> styles = new HashMap<String, XSSFCellStyle>();
    XSSFDataFormat fmt = wb.createDataFormat();

    XSSFCellStyle style1 = wb.createCellStyle();
    style1.setAlignment(HorizontalAlignment.RIGHT);
    style1.setDataFormat(fmt.getFormat("0.0%"));
    styles.put("percent", style1);

    XSSFCellStyle style2 = wb.createCellStyle();
    style2.setAlignment(HorizontalAlignment.CENTER);
    style2.setDataFormat(fmt.getFormat("0.0X"));
    styles.put("coeff", style2);

    XSSFCellStyle style3 = wb.createCellStyle();
    style3.setAlignment(HorizontalAlignment.RIGHT);
    style3.setDataFormat(fmt.getFormat("$#,##0.00"));
    styles.put("currency", style3);

    XSSFCellStyle style4 = wb.createCellStyle();
    style4.setAlignment(HorizontalAlignment.RIGHT);
    style4.setDataFormat(fmt.getFormat("mmm dd"));
    styles.put("date", style4);

    XSSFCellStyle style5 = wb.createCellStyle();
    XSSFFont headerFont = wb.createFont();
    headerFont.setBold(true);
    style5.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
    style5.setFillPattern(FillPatternType.SOLID_FOREGROUND);
    style5.setFont(headerFont);
    styles.put("header", style5);

    return styles;
}

From source file:com.ykun.commons.utils.excel.ExcelUtils.java

License:Apache License

/**
 * ??/*from  w w  w  . j  a  va  2s  .  c  o  m*/
 *
 * @param workbook Workbook
 * @return CellStyle
 */
private static CellStyle createHeaderStyle(Workbook workbook) {
    CellStyle style = workbook.createCellStyle();
    style.setAlignment(HorizontalAlignment.CENTER);
    style.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
    style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
    Font headerFont = workbook.createFont();
    headerFont.setBold(Boolean.TRUE);
    headerFont.setColor(IndexedColors.BLACK.getIndex());
    style.setFont(headerFont);
    return style;
}

From source file:com.zxy.commons.poi.excel.ExcelUtils.java

License:Apache License

/**
 * export excel//from   ww  w  . j  a v  a2s .com
 * 
 * @param sheetName sheet name
 * @param table table
 * @return Workbook
*/
@SuppressWarnings("PMD.ShortVariable")
private static Workbook exportExcel(String sheetName, Table<Integer, String, String> table) {
    Set<Integer> tableRows = table.rowKeySet();
    Set<String> tableColumns = table.columnKeySet();
    // excel
    Workbook wb = new HSSFWorkbook();

    // sheet??
    Sheet sheet = wb.createSheet(sheetName);
    // ???n?
    /*for (int i = 0; i < keys.length; i++) {
    sheet.setColumnWidth((short) i, (short) (35.7 * 150));
    }*/

    // 
    Row row = sheet.createRow((short) 0);

    // ???
    CellStyle cs = wb.createCellStyle();
    CellStyle cs2 = wb.createCellStyle();

    // ?
    Font f1 = wb.createFont();
    Font f2 = wb.createFont();

    // ????
    f1.setFontHeightInPoints((short) 10);
    f1.setColor(IndexedColors.BLACK.getIndex());
    f1.setBold(true);

    // ??
    f2.setFontHeightInPoints((short) 10);
    f2.setColor(IndexedColors.BLACK.getIndex());

    // Font f3=wb.createFont();
    // f3.setFontHeightInPoints((short) 10);
    // f3.setColor(IndexedColors.RED.getIndex());

    // ?????
    cs.setFont(f1);
    cs.setBorderLeft(BorderStyle.THIN);
    cs.setBorderRight(BorderStyle.THIN);
    cs.setBorderTop(BorderStyle.THIN);
    cs.setBorderBottom(BorderStyle.THIN);
    cs.setAlignment(HorizontalAlignment.CENTER);

    // ???
    cs2.setFont(f2);
    cs2.setBorderLeft(BorderStyle.THIN);
    cs2.setBorderRight(BorderStyle.THIN);
    cs2.setBorderTop(BorderStyle.THIN);
    cs2.setBorderBottom(BorderStyle.THIN);
    cs2.setAlignment(HorizontalAlignment.CENTER);
    // ??
    int i = 0;
    for (String tableColumn : tableColumns) {
        Cell cell = row.createCell(i);
        cell.setCellValue(tableColumn);
        cell.setCellStyle(cs);
        i++;
    }
    // ??
    for (Integer tableRow : tableRows) {
        // Row ,Cell  , Row  Cell 0
        // sheet
        checkArgument(tableRow > 0, "Row index must be greater than zero!");
        Row row1 = sheet.createRow(tableRow);
        // row
        Map<String, String> item = table.row(tableRow);
        int j = 0;
        for (Map.Entry<String, String> entry : item.entrySet()) {
            //            for(String v:item.keySet()){
            //                System.out.println(tableRow + "-" + v + "-" + item.get(v));
            Cell cell = row1.createCell(j);
            cell.setCellValue(entry.getValue());
            cell.setCellStyle(cs2);
            j++;
        }
    }
    return wb;
}

From source file:controller.VisitasController.java

public void makeRowBold(Workbook wb, Row row) {
    CellStyle style = wb.createCellStyle();//Create style
    Font font = wb.createFont();//Create font
    font.setBoldweight(Font.BOLDWEIGHT_BOLD);
    font.setColor(new HSSFColor.WHITE().getIndex());//Make font bold
    style.setFont(font);//set it to bold
    style.setAlignment(HorizontalAlignment.CENTER);
    style.setFillBackgroundColor(new HSSFColor.BLACK().getIndex());
    style.setFillForegroundColor(new HSSFColor.BLACK().getIndex());
    style.setFillPattern(FillPatternType.SOLID_FOREGROUND);

    for (int i = 0; i < row.getLastCellNum(); i++) {
        if (!row.getCell(i).getStringCellValue().equals("")) {
            row.getCell(i).setCellStyle(style);//Set the sty;e
        }/*from  w  ww  .  ja  v  a  2s. co m*/
    }
}

From source file:controller.VisitasController.java

public void centerRow(Workbook wb, Row row) {
    CellStyle style = wb.createCellStyle();
    style.setAlignment(HorizontalAlignment.CENTER);
    for (int i = 0; i < row.getLastCellNum(); i++) {
        if (row.getCell(i) != null) {
            row.getCell(i).setCellStyle(style);//Set the sty;e
        }//from  ww w. j a va 2 s .c o m
    }
}