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

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

Introduction

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

Prototype

void setBorderTop(BorderStyle border);

Source Link

Document

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

Usage

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

License:Open Source License

/**
 * Write each Node per NodeType column, starting
 *///from   w w  w. j  av a  2  s  . co  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. jav  a2s.  c om
    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  www. ja  va  2 s .com

    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();/*from   w ww.ja  v a  2s.c  o  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);
}

From source file:com.repository2excel.Main.java

License:Apache License

/**
 * @param args//from   ww  w.  j  a v  a  2  s  .com
 */
@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 www .ja  v a2 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;
}

From source file:com.siemens.sw360.exporter.ExcelExporter.java

License:Open Source License

/**
 * Create style for data cells/*  w  w w.  j a  v  a2  s  . co  m*/
 */
private static CellStyle createCellStyte(Workbook workbook) {
    CellStyle cellStyle = workbook.createCellStyle();
    cellStyle.setBorderBottom(XSSFCellStyle.BORDER_THIN);
    cellStyle.setBorderTop(XSSFCellStyle.BORDER_THIN);
    cellStyle.setBorderRight(XSSFCellStyle.BORDER_THIN);
    cellStyle.setBorderLeft(XSSFCellStyle.BORDER_THIN);
    return cellStyle;
}

From source file:com.tecnosur.util.Excel.java

private static void createCell(HSSFWorkbook wb, Row row, int column, short halign, short valign,
        String strContenido, boolean booBorde, boolean booCabecera) {
    CreationHelper ch = wb.getCreationHelper();
    Cell cell = row.createCell(column);/*  ww w. j  ava  2s  .  c  om*/
    HSSFFont cellFont = wb.createFont();
    cellFont.setFontHeightInPoints((short) 8);
    cellFont.setFontName(HSSFFont.FONT_ARIAL);
    cellFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);

    cell.setCellValue(ch.createRichTextString(strContenido));
    CellStyle cellStyle = wb.createCellStyle();
    cellStyle.setAlignment(halign);
    cellStyle.setVerticalAlignment(valign);
    cellStyle.setFont(cellFont);
    if (booBorde) {
        cellStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN);
        cellStyle.setBottomBorderColor((short) 8);
        cellStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN);
        cellStyle.setLeftBorderColor((short) 8);
        cellStyle.setBorderRight(HSSFCellStyle.BORDER_THIN);
        cellStyle.setRightBorderColor((short) 8);
        cellStyle.setBorderTop(HSSFCellStyle.BORDER_THIN);
        cellStyle.setTopBorderColor((short) 8);
    }
    if (booCabecera) {
        cellStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN);
        cellStyle.setBottomBorderColor((short) 8);
        cellStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN);
        cellStyle.setLeftBorderColor((short) 8);
        cellStyle.setBorderRight(HSSFCellStyle.BORDER_THIN);
        cellStyle.setRightBorderColor((short) 8);
        cellStyle.setBorderTop(HSSFCellStyle.BORDER_THIN);
        cellStyle.setTopBorderColor((short) 8);

        cellStyle.setFillForegroundColor(HSSFColor.GREY_25_PERCENT.index);
        cellStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
    }
    cell.setCellStyle(cellStyle);
}

From source file:com.tm.hiber.service.util.DatabaseUtil.java

/**
 *
 * @param objFile/*from w w  w  .  jav  a  2 s .co m*/
 * @param objJTable
 * @return number of records exported
 */
public int exportData(File objFile, JTable objJTable) throws FileNotFoundException, IOException {
    int response = 0;

    if (objFile == null) {
        return response;
    }

    DefaultTableModel tm = (DefaultTableModel) objJTable.getModel();
    Object[] rows = tm.getDataVector().toArray();

    JTableHeader columnNames = objJTable.getTableHeader();
    TableColumnModel columnModel = columnNames.getColumnModel();
    int columnCount = columnModel.getColumnCount();
    Vector<String> vecColumnNames = new Vector<String>();
    for (int c = 0; c < columnCount; c++) {
        vecColumnNames.add(columnModel.getColumn(c).getHeaderValue().toString());
    }

    HSSFWorkbook exportReadyWorkbook = new HSSFWorkbook();
    HSSFSheet dataSheet = exportReadyWorkbook.createSheet(getExportSheetName());

    if (vecColumnNames.size() > 0) {
        int columnCounter = 0;
        Row objHSSFColumnName = dataSheet.createRow(0);

        for (String strColumnName : vecColumnNames) {
            /* Set Header CSS */

            Cell objHSSFCell = objHSSFColumnName.createCell(columnCounter);
            objHSSFCell.setCellValue(strColumnName);
            CellStyle csll = exportReadyWorkbook.createCellStyle();
            Font objFont = exportReadyWorkbook.createFont();
            objFont.setFontName("Calibri");
            objFont.setColor(IndexedColors.BLACK.index);
            objFont.setBold(true);
            csll.setFont(objFont);
            csll.setFillBackgroundColor(HSSFColor.YELLOW.index);
            csll.setFillForegroundColor(HSSFColor.YELLOW.index);
            csll.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
            csll.setAlignment(HSSFCellStyle.ALIGN_CENTER);
            //csll.setWrapText(true);
            objHSSFCell.setCellStyle(csll);
            columnCounter++;
        }
    }

    if (rows != null && rows.length > 0) {
        /* Set Data into Sheet */
        for (int i = 0; i < rows.length; i++) {
            Vector objCellsData = (Vector) rows[i];
            Row objHSSFRow = dataSheet.createRow(i + 1);
            if (objCellsData != null && objCellsData.size() > 0) {
                for (int j = 0; j < objCellsData.size(); j++) {

                    /* Set Cell Data CSS */

                    Cell objHSSFCell = objHSSFRow.createCell(j);
                    CellStyle csll = exportReadyWorkbook.createCellStyle();
                    Font objFont = exportReadyWorkbook.createFont();
                    objFont.setColor(IndexedColors.BLACK.index);
                    objFont.setBold(false);
                    objFont.setFontName("Calibri");
                    csll.setFont(objFont);
                    csll.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
                    csll.setFillBackgroundColor(IndexedColors.WHITE.index);
                    csll.setFillForegroundColor(IndexedColors.WHITE.index);

                    csll.setAlignment(HSSFCellStyle.ALIGN_CENTER);

                    //csll.setWrapText(true);
                    csll.setBorderBottom(CellStyle.BORDER_THIN);
                    csll.setBorderTop(CellStyle.BORDER_THIN);

                    csll.setBottomBorderColor(HSSFColor.GREY_25_PERCENT.index);
                    csll.setTopBorderColor(HSSFColor.GREY_50_PERCENT.index);

                    objHSSFCell.setCellStyle(csll);
                    Object cellData = objCellsData.get(j);
                    objHSSFCell.setCellValue((String) cellData);
                }
            }
        }

        for (int i = 0; i < columnCount; i++) {
            if (i == 2) {
                dataSheet.setColumnWidth(i, 30 * 256);
            } else {
                dataSheet.autoSizeColumn(i);
            }
        }

        /* Write File */
        FileOutputStream objFileOutputStream = new FileOutputStream(objFile);
        exportReadyWorkbook.write(objFileOutputStream);
        objFileOutputStream.flush();
        objFileOutputStream.close();
        response = rows.length;
    }

    return response;
}

From source file:com.vincestyling.apkinfoextractor.core.export.ExportToExcel.java

License:Apache License

private void setBorder(CellStyle style) {
    style.setBorderRight(CellStyle.BORDER_THIN);
    style.setRightBorderColor(IndexedColors.BLACK.getIndex());
    style.setBorderLeft(CellStyle.BORDER_THIN);
    style.setLeftBorderColor(IndexedColors.BLACK.getIndex());
    style.setBorderTop(CellStyle.BORDER_THIN);
    style.setTopBorderColor(IndexedColors.BLACK.getIndex());
    style.setBorderBottom(CellStyle.BORDER_THIN);
    style.setBottomBorderColor(IndexedColors.BLACK.getIndex());
}