Example usage for org.apache.poi.hssf.usermodel HSSFCellStyle setFillPattern

List of usage examples for org.apache.poi.hssf.usermodel HSSFCellStyle setFillPattern

Introduction

In this page you can find the example usage for org.apache.poi.hssf.usermodel HSSFCellStyle setFillPattern.

Prototype

@Override
public void setFillPattern(FillPatternType fp) 

Source Link

Document

setting to one fills the cell with the foreground color...

Usage

From source file:gov.nih.nci.evs.reportwriter.formatter.AsciiToExcelFormatter.java

License:BSD License

public Boolean convert(String textfile, String delimiter, String outfile) throws Exception {

    Vector<String> headings = getColumnHeadings(textfile, delimiter);
    Vector<Integer> maxChars = getColumnMaxChars(textfile, delimiter);

    // Note: Special Case for CDISC STDM Terminology report.
    int extensible_col = -1;
    if (_specialCases_CDISC)
        extensible_col = findColumnIndicator(headings, "Extensible");

    int heading_height_multiplier = 1;
    for (int i = 0; i < maxChars.size(); i++) {
        String heading = (String) headings.elementAt(i);
        int maxCellLen = maxChars.elementAt(i);
        int maxTokenLen = getMaxTokenLength(heading);
        if (maxTokenLen > maxCellLen) {
            maxCellLen = maxTokenLen;//from  w  w w . ja  v a 2 s . c o m
            maxChars.setElementAt(new Integer(maxCellLen), i);
        }
        if (maxCellLen < MAX_CODE_WIDTH) {
            Vector<String> tokens = parseData(heading, " ");
            if (tokens.size() > heading_height_multiplier)
                heading_height_multiplier = tokens.size();
        }
    }

    Boolean[] a = findWrappedColumns(textfile, delimiter, MAX_WIDTH);
    // Note: The max column number allowed in an Excel spreadsheet is 256
    int[] b = new int[255];
    for (int i = 0; i < 255; i++) {
        b[i] = 0;
    }

    File file = new File(textfile);
    String absolutePath = file.getAbsolutePath();
    _logger.debug("Absolute Path: " + absolutePath);
    String filename = file.getName();
    _logger.debug("filename: " + filename);

    int m = filename.indexOf(".");
    String workSheetLabel = filename.substring(0, m);
    int n = workSheetLabel.indexOf("__");
    workSheetLabel = workSheetLabel.substring(0, n);
    _logger.debug("workSheetLabel: " + workSheetLabel);

    if (workSheetLabel.compareTo("") == 0)
        return Boolean.FALSE;

    String pathName = file.getPath();
    _logger.debug("Path: " + pathName);

    BufferedReader br = getBufferReader(textfile);
    FileOutputStream fout = new FileOutputStream(outfile);
    HSSFWorkbook wb = new HSSFWorkbook();

    HSSFSheet ws = wb.createSheet(workSheetLabel);
    HSSFCellStyle toprow = wb.createCellStyle();
    HSSFCellStyle highlightedrow = wb.createCellStyle();

    HSSFCellStyle cs = wb.createCellStyle();

    // Note: GF20673 shade top row
    HSSFFont font = wb.createFont();
    font.setColor(HSSFColor.BLACK.index);
    font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
    toprow.setFont(font);

    if (extensible_col == -1) {
        toprow.setFillForegroundColor(HSSFColor.GREY_25_PERCENT.index);
    } else {
        //toprow.setFillForegroundColor(HSSFColor.YELLOW.index);
        toprow.setFillForegroundColor(HSSFColor.LIGHT_YELLOW.index);
    }

    toprow.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
    toprow.setAlignment(HSSFCellStyle.VERTICAL_CENTER);
    toprow.setWrapText(true);

    highlightedrow.setFont(font);
    //highlightedrow.setFillForegroundColor(HSSFColor.SKY_BLUE.index);
    //highlightedrow.setFillForegroundColor(HSSFColor.LIGHT_BLUE.index);
    highlightedrow.setFillForegroundColor(HSSFColor.LIGHT_CORNFLOWER_BLUE.index);

    highlightedrow.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
    highlightedrow.setAlignment(HSSFCellStyle.VERTICAL_CENTER);
    // highlightedrow.setWrapText(true);

    cs.setWrapText(true);
    // cs.setAlignment(HSSFCellStyle.ALIGN_JUSTIFY);
    cs.setAlignment(HSSFCellStyle.VERTICAL_TOP);

    HSSFRow wr = null;
    int rownum = 0;
    // int baseline_height = 15;
    int baseline_height = 12;
    while (true) {
        String line = br.readLine();
        if (line == null)
            break;
        // line = line.trim(); Note: 090512 first value could be empty
        if (line.length() <= 0)
            continue;

        Vector<String> v = parseData(line, delimiter);
        wr = ws.createRow(rownum);
        // wr.setHeightInPoints(60);
        if (rownum == 0) {
            wr.setHeightInPoints(baseline_height * heading_height_multiplier);
        } else {
            wr.setHeightInPoints(baseline_height);
            if (ADJUST_HEIGHT) {
                int num_lines = getHeightInPoints(v, ADJUST_HEIGHT, MAX_CELL_WIDTH);
                wr.setHeightInPoints(baseline_height * num_lines);
            }
        }

        // Note: Special Case for CDISC STDM Terminology report.
        boolean highlight_row = false;
        if (_specialCases_CDISC)
            highlight_row = extensible_col != -1 && v.elementAt(extensible_col).trim().length() > 0;

        for (int i = 0; i < v.size(); i++) {
            HSSFCell wc = wr.createCell(i);
            if (rownum == 0) {
                wc.setCellStyle(toprow);
            } else if (a[i].equals(Boolean.TRUE)) {

                wc.setCellStyle(cs);
                wc.setCellType(HSSFCell.CELL_TYPE_STRING);

                if (highlight_row)
                    wc.setCellStyle(highlightedrow);

            } else {
                if (highlight_row)
                    wc.setCellStyle(highlightedrow);
            }

            String s = (String) v.elementAt(i);
            s = s.trim();

            if (s.length() > b[i]) {
                b[i] = s.length();
            }
            if (s.equals("")) {
                s = null;
            }

            wc.setCellValue(s);
            if (_ncitCodeColumns.contains(i) && rownum > 0 && s != null && s.length() > 0) {
                try {
                    wc.setCellFormula("HYPERLINK(\"" + getNCItCodeUrl(s) + "\", \"" + s + "\")");
                } catch (Exception e) {
                    ExceptionUtils.print(_logger, e, "The following string is too large to be a "
                            + "valid NCIt code (" + filename + "): " + s);
                }
            }
        }
        rownum++;
    }

    br.close();
    for (int i = 0; i < 255; i++) {
        if (b[i] != 0) {
            int multiplier = b[i];
            if (i < headings.size()) {
                Integer int_obj = (Integer) maxChars.elementAt(i);
                multiplier = int_obj.intValue();
            }

            // Note(GF20673): 315 is the magic number for this font and size
            int colWidth = multiplier * 315;

            // Fields like definition run long, some sanity required
            if (colWidth > 20000) {
                colWidth = 20000;
            }
            // _logger.debug("Calculated column width " + i + ": " +
            // colWidth);
            ws.setColumnWidth(i, colWidth);
        }
    }

    // Note(GF20673): Freeze top row
    ws.createFreezePane(0, 1, 0, 1);
    wb.write(fout);
    fout.close();
    return Boolean.TRUE;
}

From source file:gov.va.med.pharmacy.peps.presentation.common.displaytag.DefaultHssfExportView.java

License:Artistic License

/**
 * doExport creates excel file for download
 * @param out OutputStream//from www. j a  v a2  s .  c o  m
 * @see org.displaytag.export.BinaryExportView#doExport(java.io.OutputStream)
 * @throws IOException IOException
 * @throws JspException JspException
 */
public void doExport(OutputStream out) throws IOException, JspException {
    try {
        HSSFWorkbook wb = new HSSFWorkbook();
        sheet = wb.createSheet("Table_Export");

        int rowNum = 0;
        int colNum = 0;

        //Create a header row
        HSSFRow xlsRow = sheet.createRow(rowNum++);

        HSSFCellStyle headerStyle = wb.createCellStyle();
        headerStyle.setFillPattern(HSSFCellStyle.FINE_DOTS);
        headerStyle.setFillBackgroundColor(HSSFColor.BLUE_GREY.index);
        HSSFFont bold = wb.createFont();
        bold.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
        bold.setColor(HSSFColor.WHITE.index);
        headerStyle.setFont(bold);

        Iterator iterator = this.model.getHeaderCellList().iterator();

        while (iterator.hasNext()) {
            HeaderCell headerCell = (HeaderCell) iterator.next();

            String columnHeader = headerCell.getTitle();

            if (columnHeader == null) {
                columnHeader = StringUtils.capitalize(headerCell.getBeanPropertyName());
            }

            HSSFCell cell = xlsRow.createCell(colNum++);
            cell.setCellValue(columnHeader);
            cell.setCellStyle(headerStyle);
        }

        RowIterator rowIterator = this.model.getRowIterator(this.exportFull);

        while (rowIterator.hasNext()) {
            Row row = rowIterator.next();
            xlsRow = sheet.createRow(rowNum++);
            colNum = 0;

            // iterate on columns
            ColumnIterator columnIterator = row.getColumnIterator(this.model.getHeaderCellList());

            while (columnIterator.hasNext()) {
                Column column = columnIterator.nextColumn();

                Object value = column.getValue(this.decorated);

                HSSFCell cell = xlsRow.createCell(colNum++);

                if (value instanceof Number) {
                    Number num = (Number) value;
                    cell.setCellValue(num.doubleValue());
                } else if (value instanceof Date) {
                    cell.setCellValue((Date) value);
                } else if (value instanceof Calendar) {
                    cell.setCellValue((Calendar) value);
                } else {
                    cell.setCellValue(escapeColumnValue(value));
                }

            }
        }

        wb.write(out);

        //            new HssfTableWriter(wb).writeTable(this.model, "-1");            
        //            wb.write(out);
    } catch (Exception e) {
        throw new HssfGenerationException(e);
    }
}

From source file:guineu.database.intro.impl.WriteFile.java

License:Open Source License

/**
 * Write data in a cell of the excel file.
 *
 * @param row Cell row//from  w ww.ja  v  a2  s. c o  m
 * @param Index Cell column
 * @param data data to be writen into the cell
 */
private void setCell(HSSFRow row, int Index, Object data, HSSFColor color) {
    HSSFCell cell = row.getCell(Index);
    if (cell == null) {
        cell = row.createCell(Index);
    }
    if (data.getClass().toString().contains("String") || data.getClass().toString().contains("Boolean")) {
        cell.setCellType(HSSFCell.CELL_TYPE_STRING);
        cell.setCellValue(String.valueOf(data));
    } else if (data.getClass().toString().contains("Double")) {
        cell.setCellValue((Double) data);
    } else if (data.getClass().toString().contains("Integer")) {
        cell.setCellValue((Integer) data);
    }
    if (color != null) {
        HSSFCellStyle style1 = wb.createCellStyle();
        style1.setFillForegroundColor(color.getIndex());
        style1.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
        for (HSSFCellStyle style : styles) {
            if (style.getFillForegroundColor() == style1.getFillForegroundColor()) {
                style1 = style;
            }
        }
        if (!styles.contains(style1)) {
            this.styles.add(style1);
        }
        cell.setCellStyle(style1);
    } else {
    }
}

From source file:hr.restart.swing.raExtendedTable.java

License:Apache License

public void exportToXLS(File output) {
    String fname = output.getName();
    if (!fname.endsWith("xls") && fname.indexOf('.') < 0)
        output = new File(output.getParentFile(), fname + ".xls");
    System.out.println("exporting to XLS");
    HSSFWorkbook wb = new HSSFWorkbook();

    HSSFDataFormat df = wb.createDataFormat();

    String fontFamily = frmParam.getParam("sisfun", "excelFont", "Arial", "Font za export u Excel", true);
    if (fontFamily == null || fontFamily.length() == 0)
        fontFamily = "Arial";

    int fontSize = 10;
    String fontSizeTx = frmParam.getParam("sisfun", "excelFontSize", "10",
            "Veliina fonta za export u Excel, u tokama", true);
    if (fontSizeTx != null && Aus.getNumber(fontSizeTx) >= 6 && Aus.getNumber(fontSizeTx) <= 72)
        fontSize = Aus.getNumber(fontSizeTx);

    HSSFFont font = wb.createFont();/*from w  ww.  j a  v  a2 s .c o  m*/
    font.setFontName(fontFamily);
    font.setFontHeightInPoints((short) fontSize);

    HSSFFont fontTitle = wb.createFont();
    fontTitle.setFontName(fontFamily);
    fontTitle.setFontHeightInPoints((short) (fontSize * 1.8));

    HSSFFont fontSubtitle = wb.createFont();
    fontSubtitle.setFontName(fontFamily);
    fontSubtitle.setFontHeightInPoints((short) (fontSize * 1.5));

    HSSFCellStyle csHeader = wb.createCellStyle();
    csHeader.setFont(font);
    csHeader.setFillBackgroundColor(HSSFColor.GREY_25_PERCENT.index);
    csHeader.setFillForegroundColor(HSSFColor.GREY_25_PERCENT.index);
    csHeader.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
    csHeader.setAlignment(HSSFCellStyle.ALIGN_CENTER);
    csHeader.setDataFormat(df.getFormat("text"));

    HSSFCellStyle csFooter = wb.createCellStyle();
    csFooter.setFont(font);
    csFooter.setFillBackgroundColor(HSSFColor.GREY_25_PERCENT.index);
    csFooter.setFillForegroundColor(HSSFColor.GREY_25_PERCENT.index);
    csFooter.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
    csFooter.setAlignment(HSSFCellStyle.ALIGN_LEFT);
    csFooter.setDataFormat(df.getFormat("text"));

    HSSFCellStyle csFooterNum2 = wb.createCellStyle();
    csFooterNum2.setFont(font);
    csFooterNum2.setFillBackgroundColor(HSSFColor.GREY_25_PERCENT.index);
    csFooterNum2.setFillForegroundColor(HSSFColor.GREY_25_PERCENT.index);
    csFooterNum2.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
    csFooterNum2.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
    csFooterNum2.setDataFormat(df.getFormat("#,##0.00"));

    HSSFCellStyle csFooterNum = wb.createCellStyle();
    csFooterNum.setFont(font);
    csFooterNum.setFillBackgroundColor(HSSFColor.GREY_25_PERCENT.index);
    csFooterNum.setFillForegroundColor(HSSFColor.GREY_25_PERCENT.index);
    csFooterNum.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
    csFooterNum.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
    csFooterNum.setDataFormat(df.getFormat("#"));

    HSSFCellStyle csDate = wb.createCellStyle();
    csDate.setFont(font);
    csDate.setAlignment(HSSFCellStyle.ALIGN_CENTER);
    csDate.setDataFormat(df.getFormat("dd.mm.yyyy"));

    HSSFCellStyle csTitle = wb.createCellStyle();
    csTitle.setFont(fontTitle);
    csTitle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
    csTitle.setDataFormat(df.getFormat("text"));

    HSSFCellStyle csSubtitle = wb.createCellStyle();
    csSubtitle.setFont(fontSubtitle);
    csSubtitle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
    csSubtitle.setDataFormat(df.getFormat("text"));

    HSSFCellStyle csNum2 = wb.createCellStyle();
    csNum2.setFont(font);
    csNum2.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
    csNum2.setDataFormat(df.getFormat("#,##0.00"));

    HSSFCellStyle csNum3 = wb.createCellStyle();
    csNum3.setFont(font);
    csNum3.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
    csNum3.setDataFormat(df.getFormat("#,##0.000"));

    HSSFCellStyle csNum = wb.createCellStyle();
    csNum.setFont(font);
    csNum.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
    csNum.setDataFormat(df.getFormat("#.#"));

    HSSFCellStyle csInt = wb.createCellStyle();
    csInt.setFont(font);
    csInt.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
    csInt.setDataFormat(df.getFormat("#"));

    HSSFCellStyle csText = wb.createCellStyle();
    csText.setFont(font);
    csText.setAlignment(HSSFCellStyle.ALIGN_LEFT);
    csText.setDataFormat(df.getFormat("text"));

    repDynamicProvider dp = repDynamicProvider.getInstance();
    boolean sums = dp.hasSumRow();
    int cols = getColumnModel().getColumnCount();
    int rows = getRowCount() - (sums ? 1 : 0);

    HSSFSheet sheet = wb.createSheet();
    HSSFRow row;
    HSSFCell cell;

    short cRow = 0;

    // header and title
    row = sheet.createRow(cRow = 0);
    cell = row.createCell((short) 0);
    cell.setCellStyle(csText);
    if (cols > 1)
        sheet.addMergedRegion(new Region(cRow, (short) 0, cRow, (short) (cols - 1)));
    cell.setEncoding(wb.ENCODING_UTF_16);
    cell.setCellValue(repMemo.getrepMemo().getOneLine());

    row = sheet.createRow(++cRow);
    cell = row.createCell((short) 0);
    cell.setCellStyle(csTitle);
    if (cols > 1)
        sheet.addMergedRegion(new Region(cRow, (short) 0, cRow, (short) (cols - 1)));
    cell.setEncoding(wb.ENCODING_UTF_16);
    if (dp.getTitle().length() > 0)
        cell.setCellValue(dp.getTitle().substring(1));
    else
        cell.setCellValue("");

    if (dp.getSubtitle().length() > 0) {
        row = sheet.createRow(++cRow);
        cell = row.createCell((short) 0);
        cell.setCellStyle(csSubtitle);
        if (cols > 1)
            sheet.addMergedRegion(new Region(cRow, (short) 0, cRow, (short) (cols - 1)));
        cell.setEncoding(wb.ENCODING_UTF_16);
        cell.setCellValue(dp.getSubtitle().substring(1));
    }

    for (short c = 0; c < cols; c++)
        sheet.setColumnWidth(c, (short) (getColumnModel().getColumn(c).getWidth() * 40));

    // sections
    row = sheet.createRow(++cRow);
    int secRow = 0, firstRow = 0;

    for (int r = 0; r < rows; r++) {
        if (r == 0) {
            row = sheet.createRow(++cRow);
            for (short c = 0; c < cols; c++) {
                cell = row.createCell(c);
                cell.setCellStyle(csHeader);
                cell.setEncoding(wb.ENCODING_UTF_16);
                cell.setCellValue(getColumnModel().getColumn(c).getHeaderValue().toString());
            }
            if (firstRow == 0)
                firstRow = cRow;
            secRow = cRow;
        }
        row = sheet.createRow(++cRow);
        for (short c = 0; c < cols; c++) {
            cell = row.createCell(c);
            Object o = getValueAt(r, c);
            if (o instanceof Number) {
                if (o instanceof BigDecimal) {
                    BigDecimal bd = (BigDecimal) o;
                    if (bd.scale() == 2)
                        cell.setCellStyle(csNum2);
                    else if (bd.scale() == 3)
                        cell.setCellStyle(csNum3);
                    else
                        cell.setCellStyle(csNum);
                    cell.setCellValue(bd.doubleValue());
                } else {
                    String t = dp.getValueAt(r, c);
                    if (Aus.isDigit(t)) {
                        cell.setCellStyle(csInt);
                        cell.setCellValue(((Number) o).doubleValue());
                    } else {
                        cell.setCellStyle(csText);
                        cell.setEncoding(wb.ENCODING_UTF_16);
                        cell.setCellValue(t);
                    }
                }
            } else if (o instanceof Date) {
                cell.setCellStyle(csDate);
                cell.setCellValue((Date) o);
            } else {
                cell.setCellStyle(csText);
                cell.setEncoding(wb.ENCODING_UTF_16);
                cell.setCellValue(dp.getValueAt(r, c));
            }
        }
    }
    System.out.println("sums " + sums);
    if (sums) {
        int non = 0;
        while (non < cols && dp.getValueAt(getRowCount() - 1, non).trim().length() == 0)
            ++non;
        if (non < cols) {
            System.out.println("creating row " + non);
            row = sheet.createRow(++cRow);

            if (non > 0) {
                cell = row.createCell((short) 0);
                cell.setCellStyle(csFooter);
                cell.setEncoding(wb.ENCODING_UTF_16);
                cell.setCellValue("U K U P N O");
                if (non > 1)
                    sheet.addMergedRegion(new Region(cRow, (short) 0, cRow, (short) (non - 1)));
            }
            for (short c = (short) non; c < cols; c++) {
                cell = row.createCell(c);
                Object o = getValueAt(rows - 1, c);
                if ((o instanceof BigDecimal) && ((BigDecimal) o).scale() == 2)
                    cell.setCellStyle(csFooterNum2);
                else
                    cell.setCellStyle(csFooterNum);
                if (dp.getValueAt(getRowCount() - 1, c).trim().length() != 0)
                    cell.setCellFormula("SUBTOTAL(9;" + xlsRange(firstRow + 1, cRow, c) + ")");
                else
                    cell.setCellValue("");
            }
        }
    }
    FileOutputStream out = null;

    try {
        out = new FileOutputStream(output);
        wb.write(out);
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        if (out != null)
            try {
                out.close();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
    }
}

From source file:io.vertigo.dynamo.plugins.export.xls.XLSExporter.java

License:Apache License

private static HSSFCellStyle createHeaderCellStyle(final HSSFWorkbook workbook) {
    final HSSFCellStyle cellStyle = workbook.createCellStyle();
    final HSSFFont font = workbook.createFont();
    font.setFontHeightInPoints((short) 10);
    font.setFontName("Arial");
    font.setBoldweight(Font.BOLDWEIGHT_BOLD);
    cellStyle.setFont(font);/*from w w w .j  a  va2  s . co  m*/
    cellStyle.setBorderBottom(CellStyle.BORDER_THIN);
    cellStyle.setBorderTop(CellStyle.BORDER_THIN);
    cellStyle.setBorderLeft(CellStyle.BORDER_THIN);
    cellStyle.setBorderRight(CellStyle.BORDER_THIN);
    cellStyle.setVerticalAlignment((short) 3);
    // styleEntete.setFillPattern(HSSFCellStyle.SPARSE_DOTS);
    cellStyle.setFillPattern(CellStyle.SOLID_FOREGROUND);
    cellStyle.setFillForegroundColor(HSSFColor.GREY_40_PERCENT.index);
    // headerCellStyle.setFillBackgroundColor(HSSFColor.LIGHT_BLUE.index);
    cellStyle.setAlignment(CellStyle.ALIGN_CENTER);
    return cellStyle;
}

From source file:io.vertigo.dynamo.plugins.export.xls.XLSExporter.java

License:Apache License

private static HSSFCellStyle createRowCellStyle(final HSSFWorkbook workbook, final boolean odd) {
    final HSSFCellStyle cellStyle = workbook.createCellStyle();
    final HSSFFont font = workbook.createFont();
    font.setFontHeightInPoints((short) 10);
    font.setFontName("Arial");
    // font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
    cellStyle.setFont(font);/*from  w w  w .  ja  va  2 s .c o m*/
    cellStyle.setBorderBottom(CellStyle.BORDER_THIN);
    cellStyle.setBorderTop(CellStyle.BORDER_THIN);
    cellStyle.setBorderLeft(CellStyle.BORDER_THIN);
    cellStyle.setBorderRight(CellStyle.BORDER_THIN);
    // cellStyle.setVerticalAlignment((short)3);
    // styleEntete.setFillPattern(HSSFCellStyle.SPARSE_DOTS);
    cellStyle.setFillPattern(CellStyle.SOLID_FOREGROUND);

    cellStyle.setFillForegroundColor(odd ? HSSFColor.WHITE.index : HSSFColor.GREY_25_PERCENT.index);
    // headerCellStyle.setFillBackgroundColor(HSSFColor.LIGHT_BLUE.index);
    // cellStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
    // cellStyle.setWrapText(true);

    return cellStyle;
}

From source file:io.vertigo.quarto.plugins.export.xls.XLSExporter.java

License:Apache License

private static HSSFCellStyle createHeaderCellStyle(final HSSFWorkbook workbook) {
    final HSSFCellStyle cellStyle = workbook.createCellStyle();
    final HSSFFont font = workbook.createFont();
    font.setFontHeightInPoints((short) 10);
    font.setFontName("Arial");
    font.setBold(true);//  w  ww  .  ja v a 2 s  . c  o m
    cellStyle.setFont(font);
    cellStyle.setBorderBottom(BorderStyle.THIN);
    cellStyle.setBorderTop(BorderStyle.THIN);
    cellStyle.setBorderLeft(BorderStyle.THIN);
    cellStyle.setBorderRight(BorderStyle.THIN);
    cellStyle.setVerticalAlignment(VerticalAlignment.JUSTIFY);
    cellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
    cellStyle.setFillForegroundColor(HSSFColorPredefined.GREY_40_PERCENT.getIndex());
    cellStyle.setAlignment(HorizontalAlignment.CENTER);
    return cellStyle;
}

From source file:io.vertigo.quarto.plugins.export.xls.XLSExporter.java

License:Apache License

private static HSSFCellStyle createRowCellStyle(final HSSFWorkbook workbook, final boolean odd) {
    final HSSFCellStyle cellStyle = workbook.createCellStyle();
    final HSSFFont font = workbook.createFont();
    font.setFontHeightInPoints((short) 10);
    font.setFontName("Arial");
    cellStyle.setFont(font);//  w  ww . j  av a2s. co m
    cellStyle.setBorderBottom(BorderStyle.THIN);
    cellStyle.setBorderTop(BorderStyle.THIN);
    cellStyle.setBorderLeft(BorderStyle.THIN);
    cellStyle.setBorderRight(BorderStyle.THIN);
    cellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);

    cellStyle.setFillForegroundColor(
            odd ? HSSFColorPredefined.WHITE.getIndex() : HSSFColorPredefined.GREY_25_PERCENT.getIndex());

    return cellStyle;
}

From source file:it.cnr.ibimet.bikeclimate.backingbeans.FotovoltaicDataBean.java

public void postProcessXLS(Object document) {
    HSSFWorkbook wb = (HSSFWorkbook) document;
    HSSFSheet sheet = wb.getSheetAt(0);//  w  w  w  .j  ava 2s.c  om
    HSSFRow header = sheet.getRow(0);
    HSSFCellStyle cellStyle = wb.createCellStyle();
    cellStyle.setFillForegroundColor(HSSFColor.GREEN.index);
    cellStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);

    //Create header
    for (int i = 0; i < header.getPhysicalNumberOfCells(); i++) {
        header.getCell(i).setCellStyle(cellStyle);
        header.getCell(i).setCellValue(columns.get(i).getHeader());

    }

    //create data table

    for (int i = 1; i < sheet.getPhysicalNumberOfRows(); i++) {
        header = sheet.getRow(i);

        for (int j = 0; j < header.getPhysicalNumberOfCells(); j++) {
            header.getCell(j).setCellValue(dati.get(i).get(columns.get(j).getProperty()));
        }
    }
}

From source file:it.cnr.ibimet.bikeclimate.backingbeans.FotovoltaicDataBean.java

public void postProcessXLSStat(Object document) {
    HSSFWorkbook wb = (HSSFWorkbook) document;
    HSSFSheet sheet = wb.getSheetAt(0);/*w  w  w.ja v  a  2 s .  c om*/
    HSSFRow header = sheet.getRow(0);
    HSSFCellStyle cellStyle = wb.createCellStyle();
    cellStyle.setFillForegroundColor(HSSFColor.GREEN.index);
    cellStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);

    //Create header
    for (int i = 0; i < header.getPhysicalNumberOfCells(); i++) {
        header.getCell(i).setCellStyle(cellStyle);
        header.getCell(i).setCellValue(columnsStat.get(i).getHeader());

    }

    //create data table

    for (int i = 1; i < sheet.getPhysicalNumberOfRows(); i++) {
        header = sheet.getRow(i);

        for (int j = 0; j < header.getPhysicalNumberOfCells(); j++) {
            header.getCell(j).setCellValue(datiStat.get(i).get(columnsStat.get(j).getProperty()));
        }
    }
}