Example usage for org.apache.poi.ss.usermodel CellStyle setBorderRight

List of usage examples for org.apache.poi.ss.usermodel CellStyle setBorderRight

Introduction

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

Prototype

void setBorderRight(BorderStyle border);

Source Link

Document

set the type of border to use for the right border of the cell

Usage

From source file:com.nc.common.utils.ExcelUtil.java

License:Open Source License

/**
 * <pre>//  ww w.ja v a2 s . c o m
 * 1.  : POI UTIL
 * 2.  : POI WORKBOOK ? / String , List<Map<String, Object>> ? , List<Map<String, Object>> 
 * </pre>
 *
 * @method Name : createWorkBook
 * @param workbook, sheetName, list, colNames
 * @return Workbook
 * @throws Exception
 * 
 */
@SuppressWarnings("deprecation")
public static Workbook createWorkBook(Workbook workbook, String sheetName, List<Map<String, Object>> list,
        List<Map<String, Object>> colNames) throws Exception {
    Row row;
    Cell cell;

    /*  ? ? START */
    /* Workbook workbook = new Workbook(); */

    CellStyle titleStyle = workbook.createCellStyle();
    CellStyle cellStyle = workbook.createCellStyle();
    CellStyle contentStyle = workbook.createCellStyle();
    CellStyle contentStyle_2 = workbook.createCellStyle();

    /* ?  */
    /* ? ? */
    Font titleFont = workbook.createFont();

    titleFont.setFontHeightInPoints((short) 13);
    titleFont.setFontName("? ");

    /*  ? */
    Font colNameFont = workbook.createFont();

    colNameFont.setFontHeightInPoints((short) 10);
    colNameFont.setFontName("? ");

    /*  ? */
    Font contentFont = workbook.createFont();

    /* ? ? ?  */
    titleStyle.setFont(titleFont);

    /*   ? / ? ?  */
    cellStyle.setFillForegroundColor(HSSFColor.GREY_25_PERCENT.index); /*  ? */
    cellStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
    cellStyle.setBorderRight(HSSFCellStyle.BORDER_THIN);//? 
    cellStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN);
    cellStyle.setBorderTop(HSSFCellStyle.BORDER_THIN);
    cellStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
    cellStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN);
    cellStyle.setFont(colNameFont);

    /*   ? / ?  */
    contentStyle.setBorderRight(HSSFCellStyle.BORDER_THIN); /* ?  */
    contentStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN);
    contentStyle.setBorderTop(HSSFCellStyle.BORDER_THIN);
    contentStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN);
    contentStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
    contentStyle.setFont(contentFont);

    /*   ? / ?   */
    contentStyle_2.setBorderRight(HSSFCellStyle.BORDER_THIN); /* ?  */
    contentStyle_2.setBorderLeft(HSSFCellStyle.BORDER_THIN);
    contentStyle_2.setBorderTop(HSSFCellStyle.BORDER_THIN);
    contentStyle_2.setBorderBottom(HSSFCellStyle.BORDER_THIN);
    contentStyle_2.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
    contentStyle_2.setAlignment(HSSFCellStyle.ALIGN_LEFT);
    contentStyle_2.setFont(contentFont);

    /*  ? */
    Sheet sheet = workbook.createSheet(sheetName);

    /*  ?? */
    int sheet1_row = 0;

    List<Map<String, Object>> colList = colNames;

    /* ? START */
    row = sheet.createRow(sheet1_row);
    for (int i = 0; i < colList.size(); i++) {

        cell = row.createCell(i);
        cell.setCellValue(String.valueOf(colList.get(i).get("item" + i)));
        cell.setCellStyle(cellStyle);
    }

    sheet1_row++;

    /* ? END */
    for (Map<String, Object> map : list) {

        row = sheet.createRow(sheet1_row);

        for (int j = 0; j < colList.size(); j++) {
            cell = row.createCell(j);
            cell.setCellStyle(contentStyle);

            if (null != map.get(colList.get(j).get("item" + j))) {
                cell.setCellValue((double) map.get(String.valueOf(colList.get(j).get("item" + j))));
            } else {
                cell.setCellValue("");
            }

            /*  ? ??  */
            sheet.autoSizeColumn((short) j);
            sheet.setColumnWidth(j, (sheet.getColumnWidth(j)) + 312);
        }
        sheet1_row++;
    }
    return workbook;
}

From source file:com.ncc.excel.test.ExcelUtil.java

License:Apache License

/** 
 * ????? //from   w  w  w  .  ja v a2s . co  m
 *  
 * @param fromStyle 
 * @param toStyle 
 */
public static void copyCellStyle(CellStyle fromStyle, CellStyle toStyle) {
    toStyle.setAlignment(fromStyle.getAlignment());
    //   
    toStyle.setBorderBottom(fromStyle.getBorderBottom());
    toStyle.setBorderLeft(fromStyle.getBorderLeft());
    toStyle.setBorderRight(fromStyle.getBorderRight());
    toStyle.setBorderTop(fromStyle.getBorderTop());
    toStyle.setTopBorderColor(fromStyle.getTopBorderColor());
    toStyle.setBottomBorderColor(fromStyle.getBottomBorderColor());
    toStyle.setRightBorderColor(fromStyle.getRightBorderColor());
    toStyle.setLeftBorderColor(fromStyle.getLeftBorderColor());

    // ?  
    toStyle.setFillBackgroundColor(fromStyle.getFillBackgroundColor());
    toStyle.setFillForegroundColor(fromStyle.getFillForegroundColor());

    // ??  
    toStyle.setDataFormat(fromStyle.getDataFormat());
    toStyle.setFillPattern(fromStyle.getFillPattern());
    // toStyle.setFont(fromStyle.getFont(null));  
    toStyle.setHidden(fromStyle.getHidden());
    toStyle.setIndention(fromStyle.getIndention());//   
    toStyle.setLocked(fromStyle.getLocked());
    toStyle.setRotation(fromStyle.getRotation());//   
    toStyle.setVerticalAlignment(fromStyle.getVerticalAlignment());
    toStyle.setWrapText(fromStyle.getWrapText());

}

From source file:com.netxforge.netxstudio.server.logic.reporting.BaseComponentReportingLogic.java

License:Open Source License

public void createHeaderStructure(HSSFSheet sheet) {

    CellStyle baseStyle = this.getWorkBook().createCellStyle();
    baseStyle.setBorderTop(CellStyle.BORDER_MEDIUM);
    baseStyle.setBorderBottom(CellStyle.BORDER_MEDIUM);
    baseStyle.setBorderLeft(CellStyle.BORDER_MEDIUM);
    baseStyle.setBorderRight(CellStyle.BORDER_MEDIUM);
    baseStyle.setAlignment(CellStyle.ALIGN_LEFT);

    CellStyle typeStyle = this.getWorkBook().createCellStyle();
    typeStyle.cloneStyleFrom(baseStyle);

    Font typeFont = getWorkBook().createFont();
    typeFont.setFontHeightInPoints((short) 24);
    typeStyle.setFont(typeFont);//from   w  w  w .  j  a  v  a 2s.  co m

    HSSFRow typeRow = sheet.createRow(0);
    typeCell = typeRow.createCell(0);
    typeCell.setCellValue("<Service Type>");
    typeCell.setCellStyle(typeStyle);

    for (int i = 1; i < HEADER_CELL_SIZE; i++) {
        typeRow.createCell(i).setCellStyle(typeStyle);
    }

    CellStyle titleStyle = this.getWorkBook().createCellStyle();
    titleStyle.cloneStyleFrom(baseStyle);

    Font titleFont = getWorkBook().createFont();
    titleFont.setFontHeightInPoints((short) 16);
    titleStyle.setFont(titleFont);

    HSSFRow titleRow = sheet.createRow(1);
    titleCell = titleRow.createCell(0);
    titleCell.setCellValue("<Report title>");
    titleCell.setCellStyle(titleStyle);

    for (int i = 1; i < HEADER_CELL_SIZE; i++) {
        titleRow.createCell(i).setCellStyle(titleStyle);
    }

    HSSFRow periodRow = sheet.createRow(2);
    periodCell = periodRow.createCell(0);
    periodCell.setCellValue("<Period>");
    periodCell.setCellStyle(titleStyle);

    for (int i = 1; i < HEADER_CELL_SIZE; i++) {
        periodRow.createCell(i).setCellStyle(typeStyle);
    }

    // Merge
    sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, HEADER_CELL_SIZE - 1));
    sheet.addMergedRegion(new CellRangeAddress(1, 1, 0, HEADER_CELL_SIZE - 1));
    sheet.addMergedRegion(new CellRangeAddress(2, 2, 0, HEADER_CELL_SIZE - 1));

}

From source file:com.netxforge.netxstudio.server.logic.reporting.BaseNodeReportingLogic.java

License:Open Source License

public void createHeaderStructure(Sheet sheet) {

    CellStyle baseStyle = this.getWorkBook().createCellStyle();
    baseStyle.setBorderTop(CellStyle.BORDER_MEDIUM);
    baseStyle.setBorderBottom(CellStyle.BORDER_MEDIUM);
    baseStyle.setBorderLeft(CellStyle.BORDER_MEDIUM);
    baseStyle.setBorderRight(CellStyle.BORDER_MEDIUM);
    baseStyle.setAlignment(CellStyle.ALIGN_LEFT);

    CellStyle typeStyle = this.getWorkBook().createCellStyle();
    typeStyle.cloneStyleFrom(baseStyle);

    Font typeFont = getWorkBook().createFont();
    typeFont.setFontHeightInPoints((short) 24);
    typeStyle.setFont(typeFont);/*w  w  w  .  ja va2 s .c  o m*/

    Row typeRow = sheet.createRow(0);
    typeCell = typeRow.createCell(0);
    typeCell.setCellValue("<Service Type>");
    typeCell.setCellStyle(typeStyle);

    for (int i = 1; i < HEADER_CELL_SIZE; i++) {
        typeRow.createCell(i).setCellStyle(typeStyle);
    }

    CellStyle titleStyle = this.getWorkBook().createCellStyle();
    titleStyle.cloneStyleFrom(baseStyle);

    Font titleFont = getWorkBook().createFont();
    titleFont.setFontHeightInPoints((short) 16);
    titleStyle.setFont(titleFont);

    Row titleRow = sheet.createRow(1);
    titleCell = titleRow.createCell(0);
    titleCell.setCellValue("<Report title>");
    titleCell.setCellStyle(titleStyle);

    for (int i = 1; i < HEADER_CELL_SIZE; i++) {
        titleRow.createCell(i).setCellStyle(titleStyle);
    }

    Row periodRow = sheet.createRow(2);
    periodCell = periodRow.createCell(0);
    periodCell.setCellValue("<Period>");
    periodCell.setCellStyle(titleStyle);

    for (int i = 1; i < HEADER_CELL_SIZE; i++) {
        periodRow.createCell(i).setCellStyle(typeStyle);
    }

    // Merge
    sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, HEADER_CELL_SIZE - 1));
    sheet.addMergedRegion(new CellRangeAddress(1, 1, 0, HEADER_CELL_SIZE - 1));
    sheet.addMergedRegion(new CellRangeAddress(2, 2, 0, HEADER_CELL_SIZE - 1));

}

From source file:com.netxforge.netxstudio.server.logic.reporting.ResourceReportingEngine.java

License:Open Source License

private CellStyle createAmberBorderStyle() {
    CellStyle style = this.getWorkBook().createCellStyle();
    style.setBorderBottom(CellStyle.BORDER_THIN);
    style.setBottomBorderColor(IndexedColors.ORANGE.getIndex());
    style.setBorderLeft(CellStyle.BORDER_THIN);
    style.setLeftBorderColor(IndexedColors.ORANGE.getIndex());
    style.setBorderRight(CellStyle.BORDER_THIN);
    style.setRightBorderColor(IndexedColors.ORANGE.getIndex());
    style.setBorderTop(CellStyle.BORDER_THIN);
    style.setTopBorderColor(IndexedColors.ORANGE.getIndex());
    return style;
}

From source file:com.netxforge.netxstudio.server.logic.reporting.ResourceReportingEngine.java

License:Open Source License

private CellStyle createRedBorderStyle() {
    CellStyle style = this.getWorkBook().createCellStyle();
    style.setBorderBottom(CellStyle.BORDER_THIN);
    style.setBottomBorderColor(IndexedColors.RED.getIndex());
    style.setBorderLeft(CellStyle.BORDER_THIN);
    style.setLeftBorderColor(IndexedColors.RED.getIndex());
    style.setBorderRight(CellStyle.BORDER_THIN);
    style.setRightBorderColor(IndexedColors.RED.getIndex());
    style.setBorderTop(CellStyle.BORDER_THIN);
    style.setTopBorderColor(IndexedColors.RED.getIndex());
    return style;
}

From source file:com.netxforge.netxstudio.server.logic.reporting.RFSServiceDashboardReportingLogic.java

License:Open Source License

/**
 * Write each Node per NodeType column, starting
 *///from   w  ww.j a  v  a 2  s  .  c  o  m
@Override
protected void writeContent(Sheet sheet, Service service, Node node, int row, int column) {

    // Write the NODE.ID box.
    int newRow = NODE_ROW + (row * NODE_HEIGHT);
    int nodeColumn = NODE_COLUMN + (column * NODE_WIDTH);

    sheet.setColumnWidth(nodeColumn, 10 * 256);

    CellStyle nodeStyle = this.getWorkBook().createCellStyle();
    nodeStyle.setBorderTop(CellStyle.BORDER_MEDIUM);
    nodeStyle.setBorderBottom(CellStyle.BORDER_MEDIUM);
    nodeStyle.setBorderLeft(CellStyle.BORDER_MEDIUM);
    nodeStyle.setBorderRight(CellStyle.BORDER_MEDIUM);
    nodeStyle.setAlignment(CellStyle.ALIGN_CENTER);
    nodeStyle.setVerticalAlignment(CellStyle.VERTICAL_CENTER);

    {
        Row cellRow = sheet.getRow(newRow);
        if (cellRow == null) {
            cellRow = sheet.createRow(newRow);
        }
        Cell c1 = cellRow.createCell(nodeColumn);
        c1.setCellValue(node.getNodeID());
        c1.setCellStyle(nodeStyle);
    }
    {
        Row cellRow = sheet.getRow(newRow + 1);
        if (cellRow == null) {
            cellRow = sheet.createRow(newRow + 1);
        }
        Cell c1 = cellRow.createCell(nodeColumn);
        c1.setCellStyle(nodeStyle);
    }
    {
        Row cellRow = sheet.getRow(newRow + 2);
        if (cellRow == null) {
            cellRow = sheet.createRow(newRow + 2);
        }
        Cell c1 = cellRow.createCell(nodeColumn);
        c1.setCellStyle(nodeStyle);
    }

    sheet.addMergedRegion(new CellRangeAddress(newRow, newRow + NODE_HEIGHT - 2, nodeColumn, nodeColumn));

    // In between column.
    sheet.setColumnWidth(nodeColumn + 1, 2 * 256);

    // Write the RAG

    CellStyle ragStyle = this.getWorkBook().createCellStyle();

    ragStyle.setBorderTop(CellStyle.BORDER_THIN);
    ragStyle.setBorderBottom(CellStyle.BORDER_THIN);
    ragStyle.setBorderLeft(CellStyle.BORDER_THIN);
    ragStyle.setBorderRight(CellStyle.BORDER_THIN);
    ragStyle.setAlignment(CellStyle.ALIGN_CENTER);
    ragStyle.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
    ragStyle.setFillPattern(CellStyle.SOLID_FOREGROUND);

    int ragColumn = nodeColumn + 2;
    sheet.setColumnWidth(ragColumn, 2 * 256);

    IMonitoringSummary summary = monStateModel.summary(new NullProgressMonitor(), node,
            new IComputationContext[] { new ObjectContext<Service>(service),
                    new ObjectContext<DateTimeRange>(getPeriod()) });
    if (summary == null) {
        return;
    }
    int[] rag = summary.rag();
    {
        Row cellRow = sheet.getRow(newRow);
        if (cellRow == null) {
            cellRow = sheet.createRow(newRow);
        }
        Cell c1 = cellRow.createCell(ragColumn);

        c1.setCellValue("R");

        CellStyle rStyle = this.getWorkBook().createCellStyle();
        rStyle.cloneStyleFrom(ragStyle);
        rStyle.setFillForegroundColor(IndexedColors.RED.getIndex());
        c1.setCellStyle(rStyle);

        if (rag != null) {
            c1.setCellValue(rag[0]);
        }
    }
    {
        Row cellRow = sheet.getRow(newRow + 1);
        if (cellRow == null) {
            cellRow = sheet.createRow(newRow + 1);
        }
        Cell c1 = cellRow.createCell(ragColumn);

        c1.setCellValue("A");

        CellStyle aStyle = this.getWorkBook().createCellStyle();
        aStyle.cloneStyleFrom(ragStyle);
        aStyle.setFillForegroundColor(IndexedColors.ORANGE.getIndex());
        c1.setCellStyle(aStyle);

        if (rag != null) {
            c1.setCellValue(rag[1]);
        }
    }
    {
        Row cellRow = sheet.getRow(newRow + 2);
        if (cellRow == null) {
            cellRow = sheet.createRow(newRow + 2);
        }
        Cell c1 = cellRow.createCell(ragColumn);
        c1.setCellValue("G");
        CellStyle gStyle = this.getWorkBook().createCellStyle();
        gStyle.cloneStyleFrom(ragStyle);
        gStyle.setFillForegroundColor(IndexedColors.GREEN.getIndex());
        c1.setCellStyle(gStyle);

        if (rag != null) {
            c1.setCellValue(rag[2]);
        }

    }
    // Clean our adapted summary.
    node.eAdapters().remove(summary);

}

From source file:com.netxforge.netxstudio.server.logic.reporting.RFSServiceSummaryReportingLogic.java

License:Open Source License

private void writeSummary(Sheet sheet) {

    // Title//from w  w w .  j av a2s . co  m
    Row summaryRow = sheet.createRow(CONTENT_ROW);
    Cell summaryCell = summaryRow.createCell(2);
    summaryCell.setCellValue("Executive Summary");
    sheet.addMergedRegion(new CellRangeAddress(CONTENT_ROW, CONTENT_ROW, 2, 4));

    // Table
    CellStyle borderStyle = this.getWorkBook().createCellStyle();
    borderStyle.setBorderTop(CellStyle.BORDER_THIN);
    borderStyle.setBorderBottom(CellStyle.BORDER_THIN);
    borderStyle.setBorderLeft(CellStyle.BORDER_THIN);
    borderStyle.setBorderRight(CellStyle.BORDER_THIN);
    borderStyle.setAlignment(CellStyle.ALIGN_CENTER);
    borderStyle.setVerticalAlignment(CellStyle.VERTICAL_CENTER);

    Row headerRow = sheet.createRow(HEADER_ROW);
    {
        Cell c1 = headerRow.createCell(4);
        c1.setCellValue("Quantity");
        c1.setCellStyle(borderStyle);
    }

    {
        Cell c1 = headerRow.createCell(5);
        c1.setCellValue("RED");
        c1.setCellStyle(borderStyle);
    }

    {
        Cell c1 = headerRow.createCell(6);
        c1.setCellValue("AMBER");
        c1.setCellStyle(borderStyle);
    }

    {
        Cell c1 = headerRow.createCell(7);
        c1.setCellValue("GREEN");
        c1.setCellStyle(borderStyle);
    }

    writeServicesSummary(sheet, borderStyle);
    writeNodesSummary(sheet, borderStyle);
    writeResourcesSummary(sheet, borderStyle);

}

From source file:com.netxforge.netxstudio.server.reporting.XLSXPOIEmitter.java

License:Open Source License

public void createHeaderStructure() {

    CellStyle baseStyle = this.getWorkBook().createCellStyle();
    baseStyle.setBorderTop(CellStyle.BORDER_MEDIUM);
    baseStyle.setBorderBottom(CellStyle.BORDER_MEDIUM);
    baseStyle.setBorderLeft(CellStyle.BORDER_MEDIUM);
    baseStyle.setBorderRight(CellStyle.BORDER_MEDIUM);
    baseStyle.setAlignment(CellStyle.ALIGN_LEFT);

    CellStyle typeStyle = this.getWorkBook().createCellStyle();
    typeStyle.cloneStyleFrom(baseStyle);

    Font typeFont = getWorkBook().createFont();
    typeFont.setFontHeightInPoints((short) 24);
    typeStyle.setFont(typeFont);//from  ww w  .j a  v  a2s  . c  om

    Row typeRow = sheet.createRow(0);
    typeCell = typeRow.createCell(0);
    typeCell.setCellValue("<Service Type>");
    typeCell.setCellStyle(typeStyle);

    for (int i = 1; i < HEADER_CELL_SIZE; i++) {
        typeRow.createCell(i).setCellStyle(typeStyle);
    }

    CellStyle titleStyle = this.getWorkBook().createCellStyle();
    titleStyle.cloneStyleFrom(baseStyle);

    Font titleFont = getWorkBook().createFont();
    titleFont.setFontHeightInPoints((short) 16);
    titleStyle.setFont(titleFont);

    Row titleRow = sheet.createRow(1);
    titleCell = titleRow.createCell(0);
    titleCell.setCellValue("<Report title>");
    titleCell.setCellStyle(titleStyle);

    for (int i = 1; i < HEADER_CELL_SIZE; i++) {
        titleRow.createCell(i).setCellStyle(titleStyle);
    }

    Row periodRow = sheet.createRow(2);
    periodCell = periodRow.createCell(0);
    periodCell.setCellValue("<Period>");
    periodCell.setCellStyle(titleStyle);

    for (int i = 1; i < HEADER_CELL_SIZE; i++) {
        periodRow.createCell(i).setCellStyle(typeStyle);
    }

    // Merge
    sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, HEADER_CELL_SIZE - 1));
    sheet.addMergedRegion(new CellRangeAddress(1, 1, 0, HEADER_CELL_SIZE - 1));
    sheet.addMergedRegion(new CellRangeAddress(2, 2, 0, HEADER_CELL_SIZE - 1));
}

From source file:com.perceptive.epm.perkolcentral.bl.ExcelReportBL.java

private void setCellBorder(Workbook wb, Cell cell) {
    CellStyle style = wb.createCellStyle();
    style.setBorderBottom(CellStyle.BORDER_THIN);
    style.setBottomBorderColor(IndexedColors.BLACK.getIndex());
    style.setBorderLeft(CellStyle.BORDER_THIN);
    style.setLeftBorderColor(IndexedColors.BLACK.getIndex());
    style.setBorderRight(CellStyle.BORDER_THIN);
    style.setRightBorderColor(IndexedColors.BLACK.getIndex());
    style.setBorderTop(CellStyle.BORDER_THIN);
    style.setTopBorderColor(IndexedColors.BLACK.getIndex());

    // Create a new font and alter it.
    Font font = wb.createFont();/*  ww  w. j a v  a 2 s  .co m*/
    font.setFontHeightInPoints((short) 9);
    font.setFontName("Georgia");
    style.setFont(font);

    style.setWrapText(true);
    style.setAlignment(CellStyle.VERTICAL_CENTER);
    style.setAlignment(CellStyle.ALIGN_LEFT);
    cell.setCellStyle(style);
    cell.setCellType(Cell.CELL_TYPE_STRING);
}