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

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

Introduction

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

Prototype

void setBorderBottom(BorderStyle border);

Source Link

Document

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

Usage

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);// www  .  j a  va 2s  .  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.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   www .  j a va2  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//w  w w  .j a va2s . c o 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  a2 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.oneis.jsinterface.generate.KGenerateXLS.java

License:Mozilla Public License

@Override
protected void writeRow(int rowNumber, ArrayList<Object> row, ArrayList<Object> rowOptions, boolean isHeaderRow,
        boolean pageBreakBefore) {
    Row r = this.sheet.createRow(rowNumber);

    if (pageBreakBefore && rowNumber > 0) {
        this.sheet.setRowBreak(rowNumber - 1);
    }/* w  w w .j av  a  2 s .c  om*/

    int rowSize = row.size();
    for (int i = 0; i < rowSize; ++i) {
        Object value = row.get(i); // ConsString is checked
        if (value != null) {
            Cell c = r.createCell(i);
            if (value instanceof Number) {
                c.setCellValue(((Number) value).doubleValue());
            } else if (value instanceof CharSequence) {
                c.setCellValue(((CharSequence) value).toString());
            } else if (value instanceof Date) {
                c.setCellValue((Date) value);
                // Check to see if option is for dates only
                boolean dateAndTimeStyle = true;
                String options = (String) getOptionsFromArrayList(rowOptions, i, String.class); // ConsString is checked by getOptionsFromArrayList()
                if (options != null && options.equals("date")) {
                    dateAndTimeStyle = false;
                }
                if (dateCellStyle == null) {
                    // Only create one each of the date cell styles per workbook to save space.
                    dateCellStyle = workbook.createCellStyle();
                    dateCellStyle.setDataFormat(workbook.createDataFormat().getFormat("yyyy-mm-dd hh:mm"));
                    dateOnlyCellStyle = workbook.createCellStyle();
                    dateOnlyCellStyle.setDataFormat(workbook.createDataFormat().getFormat("yyyy-mm-dd"));
                }
                c.setCellStyle(dateAndTimeStyle ? dateCellStyle : dateOnlyCellStyle);
                // Set column width so the dates don't come out as ########## on causal viewing
                setMinimumWidth(i, dateAndTimeStyle ? DATE_AND_TIME_COLUMN_WIDTH : DATE_COLUMN_WIDTH);
            }
        }
    }

    if (isHeaderRow) {
        // Make sure the row is always on screen
        this.sheet.createFreezePane(0, 1, 0, 1);
        // Style the row
        CellStyle style = this.workbook.createCellStyle();
        style.setBorderBottom(CellStyle.BORDER_THIN);
        Font font = this.workbook.createFont();
        font.setBoldweight(Font.BOLDWEIGHT_BOLD);
        style.setFont(font);
        r.setRowStyle(style);
        // Style the cells
        for (int s = 0; s < rowSize; ++s) {
            Cell c = r.getCell(s);
            if (c == null) {
                c = r.createCell(s);
            }
            c.setCellStyle(style);
        }
    }
}

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();/*www  .j a v a 2  s  .  c  om*/
    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);
}

From source file:com.repository2excel.Main.java

License:Apache License

/**
 * @param args/* ww w  .j av  a2s  .  c o  m*/
 */
@SuppressWarnings("deprecation")
public static void main(String[] args) {
    String xmlRepositoryDefFilePath = "";

    /** Read user input */
    Scanner scnr = new Scanner(System.in);
    System.out.println("Enter fully qualified path to customCatalog.xml:");
    try {
        xmlRepositoryDefFilePath = scnr.next();
    } catch (InputMismatchException e) {
        // TODO:
    } finally {
        scnr.close();
    }

    RepositoryDefinitionReader reader = new RepositoryDefinitionReader();
    System.out.println("Begin reading XML Repository definition file...");
    HashSet<Item> items = reader.loadRepositoryDefinition(new File(xmlRepositoryDefFilePath));
    System.out.println("Finished reading XML file!");
    if (items != null && items.size() > 0) {
        System.out.println("Preparing to export " + items.size() + " items into Excel Spreadsheet...");
        SXSSFWorkbook wb = new SXSSFWorkbook(100);
        Sheet sh = wb.createSheet();

        /** Create cell styles */
        CellStyle style = wb.createCellStyle();
        style.setBorderBottom(CellStyle.BORDER_THIN);
        style.setBorderTop(CellStyle.BORDER_THIN);
        style.setBorderLeft(CellStyle.BORDER_THIN);
        style.setBorderRight(CellStyle.BORDER_THIN);

        Iterator<Item> iter = items.iterator();
        int rownum = 0;
        while (iter.hasNext()) {
            Item item = iter.next();
            Row row = sh.createRow(rownum);
            row.createCell(0, CellType.STRING).setCellValue("Item");
            row.createCell(1, CellType.STRING).setCellValue(item.getName());
            rownum++;

            row = sh.createRow(rownum);
            row.createCell(0, CellType.STRING).setCellValue("Query Cache Size");
            row.createCell(1, CellType.STRING).setCellValue(item.getQueryCacheSize());
            rownum++;

            row = sh.createRow(rownum);
            row.createCell(0, CellType.STRING).setCellValue("Item Cache Size");
            row.createCell(1, CellType.STRING).setCellValue(item.getItemCacheSize());
            rownum++;
            HashSet<Property> properties = item.getProperties();
            if (properties != null && properties.size() > 0) {
                Cell cell;
                row = sh.createRow(rownum);
                cell = row.createCell(0, CellType.STRING);
                cell.setCellStyle(style);
                cell.setCellValue("Property");

                cell = row.createCell(1, CellType.STRING);
                cell.setCellStyle(style);
                cell.setCellValue("Type");

                cell = row.createCell(2, CellType.STRING);
                cell.setCellStyle(style);
                cell.setCellValue("Readable");

                cell = row.createCell(3, CellType.STRING);
                cell.setCellStyle(style);
                cell.setCellValue("Writable");

                cell = row.createCell(4, CellType.STRING);
                cell.setCellStyle(style);
                cell.setCellValue("Hidden");

                cell = row.createCell(5, CellType.STRING);
                cell.setCellStyle(style);
                cell.setCellValue("Table");

                cell = row.createCell(6, CellType.STRING);
                cell.setCellStyle(style);
                cell.setCellValue("Column");

                Iterator<Property> pIter = properties.iterator();
                while (pIter.hasNext()) {
                    rownum++;
                    row = sh.createRow(rownum);
                    Property property = pIter.next();
                    /** 0. Name */
                    cell = row.createCell(0, CellType.STRING);
                    cell.setCellStyle(style);
                    cell.setCellValue(property.getName());

                    /** 1. Data Type */
                    cell = row.createCell(1, CellType.STRING);
                    cell.setCellStyle(style);
                    cell.setCellValue(property.getDataType());

                    /** 2. Is Readable */
                    cell = row.createCell(2, CellType.STRING);
                    cell.setCellStyle(style);
                    cell.setCellValue(property.isReadable());

                    /** 3. Is Writable */
                    cell = row.createCell(3, CellType.STRING);
                    cell.setCellStyle(style);
                    cell.setCellValue(property.isWriteable());

                    /** 4. Is Hidden */
                    cell = row.createCell(4, CellType.STRING);
                    cell.setCellStyle(style);
                    cell.setCellValue(property.isHidden());

                    /** 5. Table */
                    cell = row.createCell(5, CellType.STRING);
                    cell.setCellStyle(style);
                    cell.setCellValue(property.getTable());

                    /** 6. Column */
                    cell = row.createCell(6, CellType.STRING);
                    cell.setCellStyle(style);
                    cell.setCellValue(property.getColumn());
                }
            }
            rownum++;
            rownum++;
        }

        try {
            File f = new File("test.xlsx");
            FileOutputStream out = new FileOutputStream(f);
            wb.write(out);
            out.close();
            wb.close();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } finally {
            // dispose of temporary files backing this workbook on disk
            wb.dispose();
        }
    }
}

From source file:com.saba.CalendarDemo.java

License:Apache License

/**
 * CreateBorderedStyle : /*from ww w  .java  2  s.co  m*/
 * left , right , bottom & top borderstyle setting for sheet
 * @param wb
 * @return
 */
private static CellStyle createBorderedStyle(Workbook wb) {
    CellStyle style = wb.createCellStyle();
    style.setBorderRight(CellStyle.BORDER_THIN);
    style.setRightBorderColor(IndexedColors.BLACK.getIndex());
    style.setBorderBottom(CellStyle.BORDER_THIN);
    style.setBottomBorderColor(IndexedColors.BLACK.getIndex());
    style.setBorderLeft(CellStyle.BORDER_THIN);
    style.setLeftBorderColor(IndexedColors.BLACK.getIndex());
    style.setBorderTop(CellStyle.BORDER_THIN);
    style.setTopBorderColor(IndexedColors.BLACK.getIndex());
    return style;
}