Example usage for org.apache.poi.ss.usermodel Cell setCellStyle

List of usage examples for org.apache.poi.ss.usermodel Cell setCellStyle

Introduction

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

Prototype

void setCellStyle(CellStyle style);

Source Link

Document

Set the style for the cell.

Usage

From source file:com.biomeris.i2b2.export.engine.ExcelCreator.java

License:Open Source License

public void writePatientInfo(List<WPatientInfo> patientInfos, PatientSheetElements pse,
        boolean maskPatientids) {
    for (WPatientInfo pInfo : patientInfos) {
        Row row = currentSheet.createRow(currentSheetRow++);

        int colIndex = 0;

        if (maskPatientids) {
            String patientId = pInfo.getPatientId();
            Integer maskedId;/* w ww .  j  a va 2s.com*/
            if (maskedPatientMaps.containsKey(patientId)) {
                maskedId = maskedPatientMaps.get(patientId);
            } else {
                maskedId = nextMaskedId;
                maskedPatientMaps.put(patientId, nextMaskedId++);
            }
            row.createCell(colIndex++).setCellValue(maskedId);
        } else {
            row.createCell(colIndex++).setCellValue(pInfo.getPatientId());
        }

        if (pse == null || pse.isVitalStatus()) {
            row.createCell(colIndex++).setCellValue(pInfo.getVitalStatus());
        }

        if (pse == null || pse.isBirthDate()) {
            if (pInfo.getDateOfBirth() != null) {
                Cell cell = row.createCell(colIndex++);
                cell.setCellStyle(dateStyle);
                cell.setCellValue(pInfo.getDateOfBirth().getTime());

                row.createCell(colIndex++).setCellValue(getAge(pInfo.getDateOfBirth()));
            } else {
                colIndex = colIndex + 2;
            }
        }

        if (pse == null || pse.isDeathDate()) {
            if (pInfo.getDateOfDeath() != null) {
                Cell cell = row.createCell(colIndex++);
                cell.setCellStyle(dateStyle);
                cell.setCellValue(pInfo.getDateOfDeath().getTime());
            } else {
                colIndex++;
            }
        }
        if (pse == null || pse.isSex()) {
            if (pInfo.getSex() != null) {
                row.createCell(colIndex++).setCellValue(pInfo.getSex());
            } else {
                colIndex++;
            }
        }
        if (pse == null || pse.isLanguage()) {
            if (pInfo.getLanguage() != null) {
                row.createCell(colIndex++).setCellValue(pInfo.getLanguage());
            } else {
                colIndex++;
            }
        }
        if (pse == null || pse.isRace()) {
            if (pInfo.getRace() != null) {
                row.createCell(colIndex++).setCellValue(pInfo.getRace());
            } else {
                colIndex++;
            }
        }
        if (pse == null || pse.isMaritalStatus()) {
            if (pInfo.getMaritalStatus() != null) {
                row.createCell(colIndex++).setCellValue(pInfo.getMaritalStatus());
            } else {
                colIndex++;
            }

        }
        if (pse == null || pse.isReligion()) {
            if (pInfo.getReligion() != null) {
                row.createCell(colIndex++).setCellValue(pInfo.getReligion());
            } else {
                colIndex++;
            }

        }
        if (pse == null || pse.isZipCode()) {
            if (pInfo.getZipCode() != null) {
                row.createCell(colIndex++).setCellValue(pInfo.getZipCode());
            } else {
                colIndex++;
            }

        }
        if (pse == null || pse.isIncome()) {
            if (pInfo.getIncome() != null) {
                row.createCell(colIndex++).setCellValue(pInfo.getIncome());
            } else {
                colIndex++;
            }

        }
    }
}

From source file:com.biomeris.i2b2.export.engine.ExcelCreator.java

License:Open Source License

public void writeExportInfo(WExport export) {
    // User/*from  ww w .  j a  va 2s . co  m*/
    Row rowUser = currentSheet.createRow(currentSheetRow++);
    rowUser.createCell(0).setCellValue("User");
    rowUser.createCell(1).setCellValue(export.getUsername());

    // Export date
    Row rowDate = currentSheet.createRow(currentSheetRow++);
    rowDate.createCell(0).setCellValue("Export date");
    Cell todayCell = rowDate.createCell(1);
    todayCell.setCellStyle(dateStyle);
    todayCell.setCellValue(new Date());

    // Export type
    Row rowET = currentSheet.createRow(currentSheetRow++);
    rowET.createCell(0).setCellValue("Export type");
    rowET.createCell(1).setCellValue(export.getExportParams().getExportType());

    // Concepts and modifiers
    int conceptNum = 1;
    for (Concept c : export.getConcepts()) {
        Row rowC1 = currentSheet.createRow(currentSheetRow++);
        rowC1.createCell(0).setCellValue("Concept " + conceptNum + " (name)");
        rowC1.createCell(1).setCellValue(c.getName());
        Row rowC2 = currentSheet.createRow(currentSheetRow++);
        rowC2.createCell(0).setCellValue("Concept " + conceptNum + " (key)");
        rowC2.createCell(1).setCellValue(c.getItemKey());
        if (c.getModifier() != null) {
            Row rowM1 = currentSheet.createRow(currentSheetRow++);
            rowM1.createCell(0).setCellValue("Concept " + conceptNum + " (modifier name)");
            rowM1.createCell(1).setCellValue(c.getModifier().getName());
            Row rowM2 = currentSheet.createRow(currentSheetRow++);
            rowM2.createCell(0).setCellValue("Concept " + conceptNum + " (modifier key)");
            rowM2.createCell(1).setCellValue(c.getModifier().getModifierKey());
        }
        conceptNum++;
    }

    // Filter date ( min start date)
    if (export.getExportParams().getStartDate() != null) {
        Row rowSD = currentSheet.createRow(currentSheetRow++);
        rowSD.createCell(0).setCellValue("Min start date");
        Cell sdCell = rowSD.createCell(1);
        sdCell.setCellStyle(dateStyle);
        sdCell.setCellValue(export.getExportParams().getStartDate().getTime());
    }

    // Filter date (max start date)
    if (export.getExportParams().getEndDate() != null) {
        Row rowED = currentSheet.createRow(currentSheetRow++);
        rowED.createCell(0).setCellValue("Max start date");
        Cell sdCell = rowED.createCell(1);
        sdCell.setCellStyle(dateStyle);
        sdCell.setCellValue(export.getExportParams().getEndDate().getTime());
    }
}

From source file:com.blackducksoftware.tools.commonframework.standard.datatable.writer.DataSetWriterExcel.java

License:Apache License

private void populateHyperlinkCell(Record record, FieldDef fieldDef, Cell cell) throws Exception {
    String cellValue = record.getHyperlinkFieldValue(fieldDef.getName()).getDisplayText();
    cell.setCellValue(cellValue);//from   w w w.  jav a 2  s. co m

    // cell style for hyperlinks
    // by default hyperlinks are blue and underlined
    CellStyle hlink_style = workbook.createCellStyle();
    Font hlink_font = workbook.createFont();
    hlink_font.setUnderline(Font.U_SINGLE);
    hlink_font.setColor(IndexedColors.BLUE.getIndex());
    hlink_style.setFont(hlink_font);

    // Make it a hyperlink
    CreationHelper createHelper = workbook.getCreationHelper();
    Hyperlink link = createHelper.createHyperlink(Hyperlink.LINK_URL);
    link.setAddress(record.getHyperlinkFieldValue(fieldDef.getName()).getHyperlinkText());
    cell.setHyperlink(link);
    cell.setCellStyle(hlink_style);
}

From source file:com.blackducksoftware.tools.commonframework.standard.protex.report.template.TemplateWriter.java

License:Apache License

/**
 * Write pojo values to row for the provided sheet.
 * //  w  w w .  j a  v a 2s  . c  om
 * @param activeSheet
 *            the provided sheet for pojo values write out to the rows
 * @param activeRow
 *            the active row
 * @param pojo
 *            the pojo
 * @param columnMap
 *            the column map
 * @param cloneStyle
 *            - if true, apply the styles to the new cells
 */
private void writePojoValuesToRow(Sheet activeSheet, Row activeRow, TemplatePojo pojo,
        Map<String, TemplateColumn> columnMap, boolean cloneStyle) {

    Iterator<String> it = columnMap.keySet().iterator();
    while (it.hasNext()) {
        String key = it.next();
        TemplateColumn column = columnMap.get(key);
        Integer position = column.getColumnPos();
        CellStyle styleFromTemplate = column.getCellStyle();

        Cell activeCell;
        int cellType = column.getCellType();
        if (cellType == Cell.CELL_TYPE_FORMULA) {
            activeCell = activeRow.createCell(position, Cell.CELL_TYPE_FORMULA);
            log.debug("Active Cell is PartOfArrayFormulaGroup: " + activeCell.isPartOfArrayFormulaGroup());
        } else if (cellType == Cell.CELL_TYPE_NUMERIC) {
            activeCell = activeRow.createCell(position, Cell.CELL_TYPE_NUMERIC);
        } else {
            activeCell = activeRow.createCell(position, Cell.CELL_TYPE_STRING);
        }

        // Set the value
        String pojoValue = getValueFromPojo(pojo, column.getLookupMappingName());
        activeCell.setCellValue(pojoValue);

        // Set the cell style
        // TODO: This catches the XML Disconnected exception, but the styles come out all wrong on subsequent
        // sheets.
        // Appears to only happen in the unit tests.
        if (cloneStyle) {
            try {
                CellStyle newcs = book.createCellStyle();
                newcs.cloneStyleFrom(styleFromTemplate);
                activeCell.setCellStyle(newcs);
            } catch (Exception e) {
                log.warn("Unable to copy cell styles!" + e.getMessage());
            }
        }

        if (cellType == Cell.CELL_TYPE_FORMULA) {
            copyFormula(activeSheet, activeCell, activeRow, column);
        }
    }
}

From source file:com.catexpress.util.FormatosPOI.java

public void formatoSolicitud(Solicitud solicitud, Set<Proveedor> proveedores)
        throws FileNotFoundException, IOException {
    Workbook wb = new HSSFWorkbook();
    Sheet sheet;//from w  w w  . ja  v a  2  s  .  c o m
    int cont = 0;
    for (Proveedor proveedor : proveedores) {
        sheet = wb.createSheet(proveedor.getNombre());
        Row rTitulo = sheet.createRow(0);
        CellRangeAddress craTitulo = new CellRangeAddress(0, //first row (0-based)
                0, //last row  (0-based)
                0, //first column (0-based)
                6 //last column  (0-based)
        );
        sheet.addMergedRegion(craTitulo);
        Cell titulo = rTitulo.createCell(0);
        titulo.setCellValue("SOLICITUD DE MERCANC?A");
        titulo.setCellStyle(estiloHeader(wb, TITULO));
        rTitulo.setHeightInPoints(20);

        Row rUsuario = sheet.createRow(1);
        CellRangeAddress craUsuario = new CellRangeAddress(1, 1, 0, 6);
        sheet.addMergedRegion(craUsuario);
        Cell usuario = rUsuario.createCell(0);
        usuario.setCellValue((solicitud.getUsuario().getNombre() + " " + solicitud.getUsuario().getApPaterno()
                + " " + solicitud.getUsuario().getApMaterno()).toUpperCase());
        usuario.setCellStyle(estiloHeader(wb, USUARIO));
        rUsuario.setHeightInPoints(25);

        Row rSucursal = sheet.createRow(2);
        CellRangeAddress craSucursal = new CellRangeAddress(2, 2, 0, 6);
        sheet.addMergedRegion(craSucursal);
        Cell sucursal = rSucursal.createCell(0);
        sucursal.setCellValue("Sucursal: " + solicitud.getSucursal().getNombre());
        sucursal.setCellStyle(estiloHeader(wb, SUCURSAL));
        RegionUtil.setBorderTop(sucursal.getCellStyle().getBorderTop(), craSucursal, sheet, wb);
        RegionUtil.setBorderLeft(sucursal.getCellStyle().getBorderLeft(), craSucursal, sheet, wb);
        RegionUtil.setBorderRight(sucursal.getCellStyle().getBorderRight(), craSucursal, sheet, wb);
        RegionUtil.setBorderBottom(sucursal.getCellStyle().getBorderBottom(), craSucursal, sheet, wb);
        rSucursal.setHeightInPoints(20);

        Row rBlank = sheet.createRow(3);
        Cell blank;
        for (int i = 0; i <= 6; i++) {
            blank = rBlank.createCell(i);
            blank.setCellStyle(estiloVacio(wb));
        }

        Row rFecha = sheet.createRow(4);
        Cell labelFecha = rFecha.createCell(0);
        labelFecha.setCellValue("FECHA:");
        labelFecha.setCellStyle(estiloHeader(wb, LABEL));
        CellRangeAddress craFecha = new CellRangeAddress(4, 4, 1, 3);
        sheet.addMergedRegion(craFecha);
        Cell fecha = rFecha.createCell(1);
        fecha.setCellValue(solicitud.getFechaSolicitud());
        fecha.setCellStyle(estiloHeader(wb, FECHA));
        for (int i = 4; i <= 6; i++) {
            blank = rFecha.createCell(i);
            blank.setCellStyle(estiloVacio(wb));
        }

        Row rVigencia = sheet.createRow(5);
        Cell labelVigencia = rVigencia.createCell(0);
        labelVigencia.setCellValue("VIGENCIA:");
        labelVigencia.setCellStyle(estiloHeader(wb, LABEL));
        CellRangeAddress craVigencia = new CellRangeAddress(5, 5, 1, 3);
        sheet.addMergedRegion(craVigencia);
        Cell vigencia = rVigencia.createCell(1);
        Calendar clndr = Calendar.getInstance();
        clndr.setTime(solicitud.getFechaSolicitud());
        clndr.add(Calendar.DAY_OF_MONTH, 3);
        vigencia.setCellValue(clndr.getTime());
        vigencia.setCellStyle(estiloHeader(wb, FECHA));
        blank = rVigencia.createCell(4);
        blank.setCellStyle(estiloVacio(wb));
        Cell labelNoPedido = rVigencia.createCell(5);
        labelNoPedido.setCellValue("PEDIDO No:");
        labelNoPedido.setCellStyle(estiloCuadro(wb, AMARILLO));
        Cell noPedido = rVigencia.createCell(6);
        noPedido.setCellValue(solicitud.getId());
        noPedido.setCellStyle(estiloCuadro(wb, AMARILLO));

        Row rHoja = sheet.createRow(6);
        for (int i = 0; i <= 4; i++) {
            blank = rHoja.createCell(i);
            blank.setCellStyle(estiloVacio(wb));
        }
        Cell labelHoja = rHoja.createCell(5);
        labelHoja.setCellValue("HOJA:");
        labelHoja.setCellStyle(estiloCuadro(wb, LABEL));
        Cell hoja = rHoja.createCell(6);
        hoja.setCellValue(++cont + "/" + proveedores.size());
        hoja.setCellStyle(estiloCuadro(wb, LABEL));

        Row rProveedor = sheet.createRow(7);
        CellRangeAddress craProveedor = new CellRangeAddress(7, 8, 0, 2);
        sheet.addMergedRegion(craProveedor);
        Cell prov = rProveedor.createCell(0);
        prov.setCellValue(proveedor.getNombre());
        prov.setCellStyle(estiloProveedor(wb));
        for (int i = 3; i <= 6; i++) {
            blank = rProveedor.createCell(i);
            blank.setCellStyle(estiloVacio(wb));
        }

        Row rProveedor2 = sheet.createRow(8);
        for (int i = 3; i <= 6; i++) {
            blank = rProveedor2.createCell(i);
            blank.setCellStyle(estiloVacio(wb));
        }

        Row rTotales = sheet.createRow(9);
        for (int i = 0; i <= 1; i++) {
            blank = rTotales.createCell(i);
            blank.setCellStyle(estiloVacio(wb));
        }
        Cell labelTotales = rTotales.createCell(2);
        labelTotales.setCellValue("TOTALES: ");
        labelTotales.setCellStyle(estiloTotales(wb));
        blank = rTotales.createCell(3);
        blank.setCellStyle(estiloTotales(wb));
        Cell totalSolicitado = rTotales.createCell(4);
        totalSolicitado.setCellStyle(estiloTotales(wb));
        totalSolicitado.setCellType(CellType.FORMULA);
        totalSolicitado.setCellFormula("SUM(E12:E" + (11 + solicitud.getDetalles().size()) + ")");
        Cell totalSurtido = rTotales.createCell(5);
        totalSurtido.setCellStyle(estiloTotales(wb));
        totalSurtido.setCellType(CellType.FORMULA);
        totalSurtido.setCellFormula("SUM(F12:F" + (11 + solicitud.getDetalles().size()) + ")");
        Cell totalNegado = rTotales.createCell(6);
        totalNegado.setCellStyle(estiloTotales(wb));
        totalNegado.setCellType(CellType.FORMULA);
        totalNegado.setCellFormula("SUM(G12:G" + (11 + solicitud.getDetalles().size()) + ")");

        Row rColumnas = sheet.createRow(10);
        Cell labelCodigo = rColumnas.createCell(0);
        labelCodigo.setCellValue("CODIGO");
        labelCodigo.setCellStyle(estiloColumnas(wb, COLUMNA));
        Cell labelOpciones = rColumnas.createCell(1);
        labelOpciones.setCellValue("OPCIONES");
        labelOpciones.setCellStyle(estiloColumnas(wb, COLUMNA));
        Cell labelModelo = rColumnas.createCell(2);
        labelModelo.setCellValue("MODELO / MATERIAL / COLOR");
        labelModelo.setCellStyle(estiloColumnas(wb, COLUMNA));
        Cell labelTalla = rColumnas.createCell(3);
        labelTalla.setCellValue("TALLA");
        labelTalla.setCellStyle(estiloColumnas(wb, COLUMNA));
        Cell labelSolicitado = rColumnas.createCell(4);
        labelSolicitado.setCellValue("SOLICITADO");
        labelSolicitado.setCellStyle(estiloColumnas(wb, COLUMNA));
        Cell labelSurtido = rColumnas.createCell(5);
        labelSurtido.setCellValue("SURTIDO");
        labelSurtido.setCellStyle(estiloColumnas(wb, COLUMNA));
        Cell labelNegado = rColumnas.createCell(6);
        labelNegado.setCellValue("NEGADO");
        labelNegado.setCellStyle(estiloColumnas(wb, COLUMNA));

        Row rValues = sheet.createRow(11);
        Cell codigo;
        Cell opciones;
        Cell modelo;
        Cell talla;
        Cell solicitado;
        Cell surtido;
        Cell negado;
        for (Dsolicitud detalle : solicitud.getDetalles()) {
            if (detalle.getProducto().getProvedor().equals(proveedor)) {
                codigo = rValues.createCell(0);
                codigo.setCellValue(detalle.getProducto().getCBarras());
                codigo.setCellStyle(estiloColumnas(wb, 0));
                opciones = rValues.createCell(1);
                opciones.setCellValue(" - ");
                opciones.setCellStyle(estiloColumnas(wb, 0));
                modelo = rValues.createCell(2);
                modelo.setCellValue(detalle.getProducto().getModelo().getNombre() + " / "
                        + detalle.getProducto().getColor().getNombre());
                modelo.setCellStyle(estiloColumnas(wb, 0));
                talla = rValues.createCell(3);
                talla.setCellValue(detalle.getProducto().getTalla().getNombre());
                talla.setCellStyle(estiloColumnas(wb, 0));
                solicitado = rValues.createCell(4);
                solicitado.setCellValue(detalle.getCantidad());
                solicitado.setCellStyle(estiloColumnas(wb, 0));
                surtido = rValues.createCell(5);
                surtido.setCellStyle(estiloColumnas(wb, SURTIDO));
                negado = rValues.createCell(6);
                negado.setCellStyle(estiloColumnas(wb, 0));
            }
        }

        for (int i = 0; i <= 6; i++) {
            sheet.autoSizeColumn(i, true);
        }
    }
    // Write the output to a file
    FileOutputStream fileOut = new FileOutputStream("Solicitud" + solicitud.getId() + ".xls");
    wb.write(fileOut);
    fileOut.close();
}

From source file:com.centurylink.mdw.common.service.JsonExport.java

License:Apache License

private Row setRowValues(Sheet sheet, int row, JSONObject json, int startCol) throws JSONException {
    Row valueRow = sheet.createRow(row);
    for (int i = startCol; i < names.size(); i++) {
        Cell cell = valueRow.createCell(i);
        String name = names.get(i);
        if (json.has(name)) {
            Object jsonValue = json.get(name);
            if (jsonValue instanceof Long || jsonValue instanceof Integer) {
                cell.setCellValue(new Double(jsonValue.toString()));
            } else if (jsonValue instanceof Boolean) {
                cell.setCellValue((Boolean) jsonValue);
            } else if (jsonValue instanceof Date) {
                cell.setCellValue((Date) jsonValue);
                cell.setCellStyle(getDateCellStyle(sheet));
            } else {
                String stringVal = jsonValue.toString();
                if (stringVal != null && (name.endsWith("Date") || "date".equals(name))) {
                    // try to parse as Query date
                    try {
                        cell.setCellValue(Query.getDate(stringVal));
                        cell.setCellStyle(getDateCellStyle(sheet));
                    } catch (ParseException ex) {
                        // try StringHelper date
                        Date d = StringHelper.stringToDate(stringVal);
                        if (d == null) {
                            cell.setCellValue(stringVal);
                        } else {
                            cell.setCellValue(d);
                            cell.setCellStyle(getDateCellStyle(sheet));
                        }/*w  w  w  .  ja v  a  2s  .  c o m*/
                    }
                } else {
                    cell.setCellValue(stringVal);
                }
            }
        }
    }
    return valueRow;
}

From source file:com.clican.pluto.dataprocess.engine.processes.ExcelProcessor.java

License:LGPL

@SuppressWarnings("unchecked")
public void writeExcel(ProcessorContext context, ExcelExecBean execBean) throws Exception {
    Workbook book = null;//from   w  w  w .ja va2  s  .c  om
    InputStream is = null;
    try {
        is = execBean.getInputStream();
    } catch (FileNotFoundException e) {

    }
    if (is != null) {
        book = WorkbookFactory.create(is);
        is.close();
    } else {
        book = new HSSFWorkbook();
    }
    CreationHelper createHelper = book.getCreationHelper();
    CellStyle dateStyle = book.createCellStyle();
    dateStyle.setDataFormat(createHelper.createDataFormat().getFormat("yyyy-MM-dd"));

    CellStyle numStyle = book.createCellStyle();
    numStyle.setDataFormat(createHelper.createDataFormat().getFormat("0.00000000"));

    CellStyle intNumStyle = book.createCellStyle();
    intNumStyle.setDataFormat(createHelper.createDataFormat().getFormat("0"));

    List<Object> result = context.getAttribute(execBean.getParamName());
    String[] columns = execBean.getColumns();
    if (execBean.getColumns() != null) {
        columns = execBean.getColumns();
    } else {
        columns = ((List<String>) context.getAttribute(execBean.getColumnsVarName())).toArray(new String[] {});
    }
    String sheetName;
    if (StringUtils.isNotEmpty(execBean.getSheetName())) {
        sheetName = execBean.getSheetName();
    } else {
        sheetName = context.getAttribute(execBean.getSheetVarName()).toString();
    }
    // int number = book.getNumberOfSheets();
    Sheet sheet = book.createSheet(sheetName);
    int rowNum = 0;
    Row firstRow = sheet.createRow(rowNum++);
    for (int i = 0; i < columns.length; i++) {
        Cell cell = firstRow.createCell(i);
        cell.setCellType(Cell.CELL_TYPE_STRING);
        cell.setCellValue(columns[i]);
    }

    for (int i = 0; i < result.size(); i++) {
        Object row = result.get(i);
        Row dataRow = sheet.createRow(rowNum++);

        for (int j = 0; j < columns.length; j++) {
            Object obj = PropertyUtils.getNestedProperty(row, columns[j]);
            Cell cell = dataRow.createCell(j);
            if (obj == null) {
                cell.setCellType(Cell.CELL_TYPE_BLANK);
            } else {
                if (obj instanceof String) {
                    cell.setCellType(Cell.CELL_TYPE_STRING);
                    cell.setCellValue(obj.toString());
                } else if (obj instanceof Date) {
                    cell.setCellValue((Date) obj);
                    cell.setCellStyle(dateStyle);
                } else if (obj instanceof Integer || obj instanceof Long) {
                    cell.setCellType(Cell.CELL_TYPE_NUMERIC);
                    cell.setCellStyle(intNumStyle);
                    cell.setCellValue(new Double(obj.toString()));
                } else if (obj instanceof Number) {
                    cell.setCellType(Cell.CELL_TYPE_NUMERIC);
                    cell.setCellStyle(numStyle);
                    cell.setCellValue(new Double(obj.toString()));
                } else {
                    throw new DataProcessException("??Excel?");
                }
            }
        }
    }

    OutputStream os = null;
    try {
        os = execBean.getOutputStream();
        book.write(os);
    } finally {
        if (os != null) {
            os.close();
        }
    }
}

From source file:com.cms.utils.ExportExcell.java

/**
 * Tao cac sheet. Chua export ra file excell
 *
 * @param sheetName/*from ww w.  j av a2 s . c  o m*/
 * @param lstData
 * @param formatExcell
 * @param key
 */
public void buildSheet(String sheetName, List<?> lstData, List<FormatExcell> formatExcell, String key) {
    Sheet sheetTmp = wb.createSheet(sheetName);
    FormatExcell item;
    Row rowheader = sheetTmp.createRow(0);
    ExportExcellCelltype customCellType = new ExportExcellCelltype(wb);

    Cell cellStt = rowheader.createCell(0);
    cellStt.setCellValue(BundleUtils.getString("STT"));
    cellStt.setCellStyle(customCellType.cellTypeColumnStt());
    for (int i = 0; i < formatExcell.size(); i++) {
        item = formatExcell.get(i);
        Cell cell = rowheader.createCell(i + 1);
        cell.setCellValue(getColumnTitle(item.getCellColumn(), key));
        cell.setCellStyle(customCellType.cellTypeHeader(false));
        sheetTmp.setColumnWidth(i + 1, item.getColumnWidth());
        sheetTmp.setColumnHidden(i + 1, item.getColumnHiden());
        if (item.getHeaderCommand() != null) {
            cell.setCellComment(getcellComment(sheetTmp, item, cell));
        }
        setFormatCell(customCellType, item);
    }
    if (DataUtil.isListNullOrEmpty(formatExcell) || DataUtil.isListNullOrEmpty(lstData)) {
        return;
    }
    buildContentSheet(sheetTmp, customCellType, lstData, formatExcell);
}

From source file:com.cms.utils.ExportExcell.java

private void buildContentSheet(Sheet sheetTmp, ExportExcellCelltype customCellType, List<?> lstData,
        List<FormatExcell> formatExcell) {

    int i = 1;/*from ww w . j a  v  a 2 s  . c  o m*/
    for (Object itemData : lstData) {

        Row rowData = sheetTmp.createRow(i);
        Cell cellStt = rowData.createCell(0);
        cellStt.setCellValue(i);
        cellStt.setCellStyle(customCellType.cellTypeAlignCenter(false));
        i++;
        createCell(itemData, rowData, formatExcell);
    }
}

From source file:com.cms.utils.ExportExcell.java

public void buildSheet(List<?> lstData, List<FormatExcell> formatExcell, String key) {
    FormatExcell item;//from  w  ww. j  a  va2 s  . c o m

    Row rowheader = sh.createRow(0);
    customCellType = new ExportExcellCelltype(wb);

    Cell cellStt = rowheader.createCell(0);
    cellStt.setCellValue(BundleUtils.getString("STT"));
    cellStt.setCellStyle(customCellType.cellTypeColumnStt());
    for (int i = 0; i < formatExcell.size(); i++) {
        item = formatExcell.get(i);
        Cell cell = rowheader.createCell(i + 1);
        cell.setCellValue(getColumnTitle(item.getCellColumn(), key));
        cell.setCellStyle(customCellType.cellTypeHeader(false));
        sh.setColumnWidth(i + 1, item.getColumnWidth());
        sh.setColumnHidden(i + 1, item.getColumnHiden());
        if (item.getHeaderCommand() != null) {
            cell.setCellComment(getcellComment(item, cell));
        }
        setFormatCell(item);
    }
    if (DataUtil.isListNullOrEmpty(formatExcell) || DataUtil.isListNullOrEmpty(lstData)) {
        return;
    }
    buildContentSheet(lstData, formatExcell);

}