Example usage for org.apache.poi.hssf.usermodel HSSFSheet createRow

List of usage examples for org.apache.poi.hssf.usermodel HSSFSheet createRow

Introduction

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

Prototype

@Override
public HSSFRow createRow(int rownum) 

Source Link

Document

Create a new row within the sheet and return the high level representation

Usage

From source file:bean.StatementOfOperationsExport.java

public void export0() {
    Integer columnNo;//  w w  w .ja  v a 2 s.co m
    HSSFWorkbook workbook;
    HSSFSheet sheet;
    HSSFRow dataRow;
    HSSFCell cell;
    HSSFCellStyle cellStyle, boldStyle;
    HSSFFont font;

    ThemeDisplay themeDisplay = LiferayFacesContext.getInstance().getThemeDisplay();

    getExportData().createFolder(null, themeDisplay, "Statement of Operations Report", "DESCRIPTION");

    if (getExportData().getFilename() == null || getExportData().getFilename().length() == 0) {
        getExportData().setFilename("Default(" + new Date() + ")");
    }
    getExportData().setFilename(getExportData().getFilename().replace(":", ""));

    try {
        getExportData().setFilename(getExportData().getFilename().concat(".xls"));
        workbook = new HSSFWorkbook();

        cellStyle = workbook.createCellStyle();
        cellStyle.setDataFormat(HSSFDataFormat.getBuiltinFormat("#,##0.00"));

        font = workbook.createFont();
        font.setBoldweight(Font.BOLDWEIGHT_BOLD);

        boldStyle = workbook.createCellStyle();
        boldStyle.setFont(font);

        sheet = workbook.createSheet(
                "Statement of Operations Report " + getFinancialReportData().getCurrentMonth() != null
                        ? getDataConvert().monthConvert(getFinancialReportData().getCurrentMonth()) + " "
                                + getFinancialReportData().getCurrentYear().toString()
                        : getFinancialReportData().getCurrentYear().toString());

        dataRow = sheet.createRow((short) 0);
        columnNo = 0;
        cell = dataRow.createCell(columnNo++);
        cell.setCellValue("STATEMENT OF OPERATIONS");
        cell.setCellStyle(boldStyle);

        dataRow = sheet.createRow(dataRow.getRowNum() + 1);
        columnNo = 0;
        cell = dataRow.createCell(columnNo++);
        cell.setCellValue(getFinancialReportData().getCurrentMonth() != null
                ? getDataConvert().monthConvert(getFinancialReportData().getCurrentMonth()) + " "
                        + getFinancialReportData().getCurrentYear().toString()
                : getFinancialReportData().getCurrentYear().toString());
        cell.setCellStyle(boldStyle);

        dataRow = sheet.createRow(dataRow.getRowNum() + 1);

        dataRow = sheet.createRow(dataRow.getRowNum() + 1);
        columnNo = 0;
        cell = dataRow.createCell(columnNo++);
        cell.setCellValue("INCOME");
        cell.setCellStyle(boldStyle);
        //                      

        for (int i = 0; i < getStatementOfOperationsData().getIncomeLevel2().size(); i++) {
            dataRow = sheet.createRow(dataRow.getRowNum() + 1);
            columnNo = 0;

            cell = dataRow.createCell(columnNo++);
            cell.setCellValue(getStatementOfOperationsData().getIncomeLevel2().get(i).getAcctTitle());
            cell.setCellStyle(boldStyle);
            //                
            dataRow.createCell(columnNo++).setCellValue("");
            if (getStatementOfOperationsData().getIncomeLevel3().get(i).isEmpty()) {
                cell = dataRow.createCell(columnNo++);
                cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC);
                cell.setCellValue(
                        getStatementOfOperationsData().getIncomeLevel2().get(i).getAmount().doubleValue());
                cell.setCellStyle(cellStyle);
            }
            //                
            for (int ii = 0; ii < getStatementOfOperationsData().getIncomeLevel3().get(i).size(); ii++) {
                dataRow = sheet.createRow(dataRow.getRowNum() + 1);
                columnNo = 0;

                dataRow.createCell(columnNo++).setCellValue("");
                dataRow.createCell(columnNo++).setCellValue(
                        getStatementOfOperationsData().getIncomeLevel3().get(i).get(ii).getAcctTitle());

                cell = dataRow.createCell(columnNo++);
                cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC);
                cell.setCellValue(getStatementOfOperationsData().getIncomeLevel3().get(i).get(ii).getAmount()
                        .doubleValue());
                cell.setCellStyle(cellStyle);

                if (ii == getStatementOfOperationsData().getIncomeLevel3().get(i).size() - 1) {
                    dataRow = sheet.createRow(dataRow.getRowNum() + 1);
                    columnNo = 0;

                    dataRow.createCell(columnNo++).setCellValue("");

                    cell = dataRow.createCell(columnNo++);
                    cell.setCellValue("TOTAL");
                    cell.setCellStyle(boldStyle);

                    cell = dataRow.createCell(columnNo++);
                    cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC);
                    cell.setCellValue(
                            getStatementOfOperationsData().getIncomeLevel2Total().get(i).doubleValue());
                    cell.setCellStyle(cellStyle);
                }
            }

            if (i == getStatementOfOperationsData().getIncomeLevel2().size() - 1) {
                dataRow = sheet.createRow(dataRow.getRowNum() + 1);
                columnNo = 0;

                cell = dataRow.createCell(columnNo++);
                cell.setCellValue("TOTAL INCOME");
                cell.setCellStyle(boldStyle);

                dataRow.createCell(columnNo++).setCellValue("");

                cell = dataRow.createCell(columnNo++);
                cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC);
                //                    cell.setCellValue(getStatementOfOperationsData().getIncomeLevel2Total().get(i).doubleValue());
                cell.setCellValue(getStatementOfOperationsData().getIncomeLevel1Total().doubleValue());
                cell.setCellStyle(cellStyle);
            }
        }

        //            
        dataRow = sheet.createRow(dataRow.getRowNum() + 1);

        dataRow = sheet.createRow(dataRow.getRowNum() + 1);
        columnNo = 0;
        cell = dataRow.createCell(columnNo++);
        cell.setCellValue("EXPENSES");
        cell.setCellStyle(boldStyle);
        //            

        for (int i = 0; i < getStatementOfOperationsData().getExpensesLevel2().size(); i++) {
            dataRow = sheet.createRow(dataRow.getRowNum() + 1);
            columnNo = 0;

            cell = dataRow.createCell(columnNo++);
            cell.setCellValue(getStatementOfOperationsData().getExpensesLevel2().get(i).getAcctTitle());
            cell.setCellStyle(boldStyle);
            //                
            dataRow.createCell(columnNo++).setCellValue("");
            if (getStatementOfOperationsData().getExpensesLevel3().get(i).isEmpty()) {
                cell = dataRow.createCell(columnNo++);
                cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC);
                cell.setCellValue(
                        getStatementOfOperationsData().getExpensesLevel2().get(i).getAmount().doubleValue());
                cell.setCellStyle(cellStyle);
            }
            //                             
            for (int ii = 0; ii < getStatementOfOperationsData().getExpensesLevel3().get(i).size(); ii++) {
                dataRow = sheet.createRow(dataRow.getRowNum() + 1);
                columnNo = 0;

                dataRow.createCell(columnNo++).setCellValue("");
                dataRow.createCell(columnNo++).setCellValue(
                        getStatementOfOperationsData().getExpensesLevel3().get(i).get(ii).getAcctTitle());

                cell = dataRow.createCell(columnNo++);
                cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC);
                cell.setCellValue(getStatementOfOperationsData().getExpensesLevel3().get(i).get(ii).getAmount()
                        .doubleValue());
                cell.setCellStyle(cellStyle);

                if (ii == getStatementOfOperationsData().getExpensesLevel3().get(i).size() - 1) {
                    dataRow = sheet.createRow(dataRow.getRowNum() + 1);
                    columnNo = 0;

                    dataRow.createCell(columnNo++).setCellValue("");

                    cell = dataRow.createCell(columnNo++);
                    cell.setCellValue("TOTAL");
                    cell.setCellStyle(boldStyle);

                    cell = dataRow.createCell(columnNo++);
                    cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC);
                    cell.setCellValue(
                            getStatementOfOperationsData().getExpensesLevel2Total().get(i).doubleValue());
                    cell.setCellStyle(cellStyle);
                }
            }

            if (i == getStatementOfOperationsData().getExpensesLevel2().size() - 1) {
                dataRow = sheet.createRow(dataRow.getRowNum() + 1);
                columnNo = 0;

                cell = dataRow.createCell(columnNo++);
                cell.setCellValue("TOTAL EXPENSES");
                cell.setCellStyle(boldStyle);

                dataRow.createCell(columnNo++).setCellValue("");

                cell = dataRow.createCell(columnNo++);
                cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC);
                //                    cell.setCellValue(getStatementOfOperationsData().getExpensesLevel2Total().get(i).doubleValue());
                cell.setCellValue(getStatementOfOperationsData().getExpenseLevel1Total().doubleValue());
                cell.setCellStyle(cellStyle);
            }
        }

        FileOutputStream fileOutputStream = new FileOutputStream(getExportData().getFilename());
        workbook.write(fileOutputStream);
        fileOutputStream.close();

        getExportData().fileUploadByDL(getExportData().getFilename(), "Statement of Operations Report",
                themeDisplay, null);

        File file = new File(getExportData().getFilename());
        if (file.exists()) {
            file.delete();
        }
    } catch (Exception e) {
        System.out.print("statementOfOperationsExport().export0() " + e);
        FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR, "Error",
                "An error occurred while generating excel file.");
        FacesContext.getCurrentInstance().addMessage(null, message);
    }
}

From source file:bean.TrialBalanceExport.java

public void export() {
    Integer columnNo;//from  w w w .j  av a  2  s.  co  m
    HSSFWorkbook workbook;
    HSSFSheet sheet;
    HSSFRow dataRow;
    HSSFCell cell;
    HSSFCellStyle cellStyle, boldStyle;
    HSSFFont font;

    ThemeDisplay themeDisplay = LiferayFacesContext.getInstance().getThemeDisplay();

    getExportData().createFolder(null, themeDisplay, "Trial Balance Report", "DESCRIPTION");

    if (getExportData().getFilename() == null || getExportData().getFilename().length() == 0) {
        getExportData().setFilename("Default(" + new Date() + ")");
    }
    getExportData().setFilename(getExportData().getFilename().replace(":", ""));

    try {
        getExportData().setFilename(getExportData().getFilename().concat(".xls"));
        workbook = new HSSFWorkbook();

        cellStyle = workbook.createCellStyle();
        cellStyle.setDataFormat(HSSFDataFormat.getBuiltinFormat("#,##0.00"));

        font = workbook.createFont();
        font.setBoldweight(Font.BOLDWEIGHT_BOLD);

        boldStyle = workbook.createCellStyle();
        boldStyle.setFont(font);

        sheet = workbook
                .createSheet("Trial Balance Report " + getFinancialReportData().getCurrentMonth() != null
                        ? getDataConvert().monthConvert(getFinancialReportData().getCurrentMonth()) + " "
                                + getFinancialReportData().getCurrentYear().toString()
                        : getFinancialReportData().getCurrentYear().toString());

        dataRow = sheet.createRow((short) 0);
        columnNo = 0;
        cell = dataRow.createCell(columnNo++);
        cell.setCellValue("TRIAL BALANCE");
        cell.setCellStyle(boldStyle);

        dataRow = sheet.createRow(dataRow.getRowNum() + 1);
        columnNo = 0;
        cell = dataRow.createCell(columnNo++);
        cell.setCellValue(getFinancialReportData().getCurrentMonth() != null
                ? getDataConvert().monthConvert(getFinancialReportData().getCurrentMonth()) + " "
                        + getFinancialReportData().getCurrentYear().toString()
                : getFinancialReportData().getCurrentYear().toString());
        cell.setCellStyle(boldStyle);

        dataRow = sheet.createRow(dataRow.getRowNum() + 1);

        dataRow = sheet.createRow(dataRow.getRowNum() + 1);
        columnNo = 0;
        cell = dataRow.createCell(columnNo++);
        cell.setCellValue("Account Title");
        cell.setCellStyle(boldStyle);

        columnNo = 1;
        cell = dataRow.createCell(columnNo++);
        cell.setCellValue("Debit");
        cell.setCellStyle(boldStyle);

        columnNo = 2;
        cell = dataRow.createCell(columnNo++);
        cell.setCellValue("Credit");
        cell.setCellStyle(boldStyle);

        if (getTrialBalanceData().getType() == 1) {
            for (int i = 0; i < getTrialBalanceData().getCombotb().size(); i++) {
                for (int ii = 0; ii < getTrialBalanceData().getCombotb().get(i).size(); ii++) {
                    dataRow = sheet.createRow(dataRow.getRowNum() + 1);
                    columnNo = 0;

                    cell = dataRow.createCell(columnNo++);
                    cell.setCellValue(getDataConvert()
                            .accountCodeConvert((String) getTrialBalanceData().getCombotb().get(i).get(ii)[0]));
                    cell.setCellStyle(cellStyle);
                    //                
                    dataRow.createCell(columnNo++).setCellValue("");

                    columnNo = 1;

                    cell = dataRow.createCell(columnNo++);
                    cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC);
                    cell.setCellValue(
                            ((BigDecimal) getTrialBalanceData().getCombotb().get(i).get(ii)[1]).doubleValue());
                    cell.setCellStyle(cellStyle);

                    columnNo = 2;

                    cell = dataRow.createCell(columnNo++);
                    cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC);
                    cell.setCellValue(
                            ((BigDecimal) getTrialBalanceData().getCombotb().get(i).get(ii)[2]).doubleValue());
                    cell.setCellStyle(cellStyle);
                }

                if (i == getTrialBalanceData().getCombotb().size() - 1) {
                    dataRow = sheet.createRow(dataRow.getRowNum() + 1);
                    dataRow = sheet.createRow(dataRow.getRowNum() + 1);
                    columnNo = 0;

                    cell = dataRow.createCell(columnNo++);
                    cell.setCellValue("TOTAL:");
                    cell.setCellStyle(boldStyle);

                    dataRow.createCell(columnNo++).setCellValue("");

                    columnNo = 1;

                    cell = dataRow.createCell(columnNo++);
                    cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC);
                    cell.setCellValue(((getTrialBalanceData().getComboDebitTotal()).doubleValue()));
                    cell.setCellStyle(boldStyle);
                    System.out.println("debit total "
                            + getDataConvert().convertAmount(getTrialBalanceData().getComboDebitTotal()));

                    columnNo = 2;

                    cell = dataRow.createCell(columnNo++);
                    cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC);
                    cell.setCellValue(((getTrialBalanceData().getComboCreditTotal()).doubleValue()));
                    cell.setCellStyle(boldStyle);
                    System.out.println("credit total "
                            + getDataConvert().convertAmount(getTrialBalanceData().getComboCreditTotal()));
                }
            }

        } else if (getTrialBalanceData().getType() == 2) {
            for (int i = 0; i < getTrialBalanceData().getTrialBalance().size(); i++) {
                dataRow = sheet.createRow(dataRow.getRowNum() + 1);
                columnNo = 0;

                cell = dataRow.createCell(columnNo++);
                cell.setCellValue((String) getTrialBalanceData().getTrialBalance().get(i).getAcctTitle());
                cell.setCellStyle(cellStyle);
                //                
                dataRow.createCell(columnNo++).setCellValue("");

                columnNo = 1;

                cell = dataRow.createCell(columnNo++);
                cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC);
                cell.setCellValue(getDataConvert()
                        .convertAmount((BigDecimal) getTrialBalanceData().getTrialBalance().get(i).getDebit()));
                cell.setCellStyle(cellStyle);

                columnNo = 2;

                cell = dataRow.createCell(columnNo++);
                cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC);
                cell.setCellValue(getDataConvert().convertAmount(
                        (BigDecimal) getTrialBalanceData().getTrialBalance().get(i).getCredit()));
                cell.setCellStyle(cellStyle);

                if (i == getTrialBalanceData().getTrialBalance().size() - 1) {
                    dataRow = sheet.createRow(dataRow.getRowNum() + 1);
                    dataRow = sheet.createRow(dataRow.getRowNum() + 1);
                    columnNo = 0;

                    cell = dataRow.createCell(columnNo++);
                    cell.setCellValue("TOTAL:");
                    cell.setCellStyle(boldStyle);

                    dataRow.createCell(columnNo++).setCellValue("");

                    columnNo = 1;

                    cell = dataRow.createCell(columnNo++);
                    cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC);
                    cell.setCellValue(
                            getDataConvert().convertAmount(getTrialBalanceData().getTrialBalanceDebitTotal()));
                    cell.setCellStyle(boldStyle);

                    columnNo = 2;

                    cell = dataRow.createCell(columnNo++);
                    cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC);
                    cell.setCellValue(
                            getDataConvert().convertAmount(getTrialBalanceData().getTrialBalanceCreditTotal()));
                    cell.setCellStyle(boldStyle);
                }
            }
        }

        FileOutputStream fileOutputStream = new FileOutputStream(getExportData().getFilename());
        workbook.write(fileOutputStream);
        fileOutputStream.close();

        getExportData().fileUploadByDL(getExportData().getFilename(), "Trial Balance Report", themeDisplay,
                null);

        File file = new File(getExportData().getFilename());
        if (file.exists()) {
            file.delete();
        }
    } catch (Exception e) {
        System.out.print("trialBalanceExport().export() " + e);
        FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR, "Error",
                "An error occurred while generating excel file.");
        FacesContext.getCurrentInstance().addMessage(null, message);
    }
}

From source file:binky.reportrunner.engine.renderers.exporters.TabbedXLSExporter.java

License:Open Source License

@SuppressWarnings("deprecation")
@Override//ww w.j  a va  2  s  .  c o m
public void export(ResultSet resultSet, String label, OutputStream outputStream) throws ExportException {

    if (this.outputStream == null)
        this.outputStream = outputStream;

    try {
        if (wb == null) {
            logger.trace("creating new workbook");
            wb = new HSSFWorkbook();
        }

        logger.trace("creaing worksheet " + label);
        HSSFSheet sheet = wb.createSheet(label);
        ResultSetMetaData metaData;

        metaData = resultSet.getMetaData();

        short rowCount = 0;
        // logger.debug("writing header");
        HSSFRow headerRow = sheet.createRow(rowCount);
        for (int i = 1; i <= metaData.getColumnCount(); i++) {
            // TODO:fix
            HSSFCell cell = headerRow.createCell((short) (i - 1));
            HSSFRichTextString string = new HSSFRichTextString(metaData.getColumnName(i));
            string.applyFont(HSSFFont.BOLDWEIGHT_BOLD);
            cell.setCellValue(string);
        }

        while (resultSet.next()) {
            rowCount++;
            HSSFRow row = sheet.createRow(rowCount);
            for (int i = 1; i <= metaData.getColumnCount(); i++) {
                // TODO:fix
                HSSFCell cell = row.createCell((short) (i - 1));

                // TODO:make this better by using types
                HSSFRichTextString string = new HSSFRichTextString("" + resultSet.getObject(i));
                cell.setCellValue(string);

            }
        }

    } catch (SQLException e) {
        throw new ExportException(e.getMessage(), e);
    }
}

From source file:binky.reportrunner.engine.renderers.exporters.XLSExporter.java

License:Open Source License

@SuppressWarnings("deprecation")
@Override//  w  w  w. ja v  a  2s. co m
public void export(ResultSet resultSet, String label, OutputStream outputStream) throws ExportException {
    try {
        HSSFWorkbook wb = new HSSFWorkbook();
        HSSFSheet sheet = wb.createSheet("Report");
        ResultSetMetaData metaData;

        metaData = resultSet.getMetaData();

        short rowCount = 0;
        // logger.debug("writing header");
        HSSFRow headerRow = sheet.createRow(rowCount);
        for (int i = 1; i <= metaData.getColumnCount(); i++) {
            //TODO:fix
            HSSFCell cell = headerRow.createCell((short) (i - 1));
            HSSFRichTextString string = new HSSFRichTextString(metaData.getColumnName(i));
            string.applyFont(HSSFFont.BOLDWEIGHT_BOLD);
            cell.setCellValue(string);
        }

        while (resultSet.next()) {
            rowCount++;
            HSSFRow row = sheet.createRow(rowCount);
            for (int i = 1; i <= metaData.getColumnCount(); i++) {
                //TODO:fix
                HSSFCell cell = row.createCell((short) (i - 1));

                // TODO:make this better by using types
                HSSFRichTextString string = new HSSFRichTextString("" + resultSet.getObject(i));
                cell.setCellValue(string);

            }
        }

        // Write the output to the stream file
        wb.write(outputStream);
        outputStream.flush();

    } catch (SQLException e) {
        throw new ExportException(e.getMessage(), e);
    } catch (IOException e) {
        throw new ExportException(e.getMessage(), e);
    }
}

From source file:br.com.deltex.sqlexecutor.core.controller.SqlExecutorController.java

public void exportExcel() throws FileNotFoundException, IOException {
    // create a new workbook       
    HSSFWorkbook workBook = new HSSFWorkbook();
    // create a new sheet
    HSSFSheet sheet = workBook.createSheet();
    // declare a row object reference
    HSSFRow row = null;//from   w  w  w .  j av  a 2s  .co  m
    // declare a cell object reference
    HSSFCell cell = null;

    int rowIndex = 0;
    int cellIndex = 0;

    try {
        for (List<String> rowDataQuery : this.dataQuery) {
            row = sheet.createRow(rowIndex);

            for (String column : rowDataQuery) {
                cell = row.createCell(cellIndex);
                cell.setCellValue(column);

                cellIndex++;
            }
            cellIndex = 0;
            rowIndex++;
        }

        // create a new file
        FileOutputStream out = new FileOutputStream(
                new File("C:/Users/harlan.bruno.santos/Desktop/workbook.xls"));

        workBook.write(out);
        out.close();
    } catch (FileNotFoundException e) {
        logger.error(e.getMessage(), e);
        throw e;
    } catch (IOException e) {
        logger.error(e.getMessage(), e);
        throw e;
    }
}

From source file:br.com.hslife.orcamento.controller.LancamentoContaController.java

License:Open Source License

@SuppressWarnings("resource")
public void exportarLancamentos() {
    if (listEntity == null || listEntity.isEmpty()) {
        warnMessage("Listagem vazio. Nada a exportar.");
    }/*from www.  j  av a2  s  .  c o m*/

    try {

        HSSFWorkbook excel = new HSSFWorkbook();
        HSSFSheet planilha = excel.createSheet("lancamentoConta");

        HSSFRow linha = planilha.createRow(0);

        HSSFCell celula = linha.createCell(0);
        celula.setCellValue("Data");
        celula = linha.createCell(1);
        celula.setCellValue("Histrico");
        celula = linha.createCell(2);
        celula.setCellValue("Valor");

        int linhaIndex = 1;
        for (LancamentoConta l : listEntity) {
            linha = planilha.createRow(linhaIndex);

            celula = linha.createCell(0);
            celula.setCellValue(Util.formataDataHora(l.getDataPagamento(), Util.DATA));

            celula = linha.createCell(1);
            celula.setCellValue(l.getDescricao());

            celula = linha.createCell(2);
            celula.setCellValue(l.getValorPago());

            linhaIndex++;
        }

        HttpServletResponse response = (HttpServletResponse) FacesContext.getCurrentInstance()
                .getExternalContext().getResponse();
        response.setContentType("application/vnd.ms-excel");
        response.setHeader("Content-Disposition", "attachment; filename=lancamentoConta.xls");
        response.setContentLength(excel.getBytes().length);
        ServletOutputStream output = response.getOutputStream();
        output.write(excel.getBytes(), 0, excel.getBytes().length);
        FacesContext.getCurrentInstance().responseComplete();

    } catch (IOException e) {
        errorMessage(e.getMessage());
    }
}

From source file:br.com.muranodesign.resources.AlunoVariavelResource.java

License:Creative Commons License

/**
 * Gerar relatrio de aluno variavel/*from  ww w . j a v a 2s. c  o  m*/
 * @param Tutoria
 * @param Ano
 * @param Periodo
 * @param Nome
 * @param Sexo
 * @param Datanascimento
 * @param Endereco
 * @param TelefoneResidencial
 * @param TelefoneCelular
 * @param email
 * @param NomeResponsavel
 * @param ParentescoResponsavel
 * @param TelefoneResidencialResponsavel
 * @param TelefoneCelularResponsavel
 * @param TelefoneComercialResponsavel
 * @param emailResponsavel
 * @param NomeMae
 * @param EnderecoMae
 * @param TelefoneCelularMae
 * @param TelefoneResidencialMae
 * @param TelefoneComercialMae
 * @param emailMae
 * @return list
 */
@Path("Relatorio")
@POST
@Produces("application/json")
public List<String> relatorio(@FormParam("Tutoria") int Tutoria, @FormParam("Ano") int Ano,
        @FormParam("Periodo") int Periodo, @FormParam("Neces") String Neces, @FormParam("Prog") String Prog,
        @FormParam("Status") String Status,

        @FormParam("tutoria") String tut, @FormParam("Nome") String Nome, @FormParam("Sexo") String Sexo,
        @FormParam("Datanascimento") String Datanascimento, @FormParam("Endereco") String Endereco,
        @FormParam("TelefoneResidencial") String TelefoneResidencial,
        @FormParam("TelefoneCelular") String TelefoneCelular, @FormParam("email") String email,
        @FormParam("NomeResponsavel") String NomeResponsavel,
        @FormParam("ParentescoResponsavel") String ParentescoResponsavel,
        @FormParam("TelefoneResidencialResponsavel") String TelefoneResidencialResponsavel,
        @FormParam("TelefoneCelularResponsavel") String TelefoneCelularResponsavel,
        @FormParam("TelefoneComercialResponsavel") String TelefoneComercialResponsavel,
        @FormParam("emailResponsavel") String emailResponsavel, @FormParam("NomeMae") String NomeMae,
        @FormParam("EnderecoMae") String EnderecoMae,
        @FormParam("TelefoneCelularMae") String TelefoneCelularMae,
        @FormParam("TelefoneResidencialMae") String TelefoneResidencialMae,
        @FormParam("TelefoneComercialMae") String TelefoneComercialMae,
        @FormParam("emailMae") String emailMae) {

    HSSFWorkbook workbook = new HSSFWorkbook();
    HSSFSheet firstSheet = workbook.createSheet("Relatorio Aluno");

    FileOutputStream fos = null;

    String nomeArquivo;

    try {

        nomeArquivo = new StringUtil().geraNomeAleatorio("xls", 15);
        fos = new FileOutputStream(new File("/home/tomcat/webapps/files/" + nomeArquivo));
        //fos = new FileOutputStream(new File("C:/Users/murano/Desktop/Teste/" + nomeArquivo));      

        HSSFRow row = firstSheet.createRow(0);

        List<String> retorno = new ArrayList<String>();
        List<List<String>> listRetorno = new ArrayList<List<String>>();

        int h = 0;
        row = firstSheet.createRow(h);
        row.createCell((short) 0).setCellValue("Tutoria");
        row.createCell((short) 1).setCellValue("Nome");
        row.createCell((short) 2).setCellValue("Sexo");
        row.createCell((short) 3).setCellValue("Datanascimento");
        row.createCell((short) 4).setCellValue("Endereco");
        row.createCell((short) 5).setCellValue("TelefoneResidencial");
        row.createCell((short) 6).setCellValue("TelefoneCelular");
        row.createCell((short) 7).setCellValue("email");
        row.createCell((short) 8).setCellValue("NomeResponsavel");
        row.createCell((short) 9).setCellValue("ParentescoResponsavel");
        row.createCell((short) 10).setCellValue("TelefoneResidencialResponsavel");
        row.createCell((short) 11).setCellValue("TelefoneCelularResponsavel");
        row.createCell((short) 12).setCellValue("TelefoneComercialResponsavel");
        row.createCell((short) 13).setCellValue("emailResponsavel");
        row.createCell((short) 14).setCellValue("NomeMae");
        row.createCell((short) 15).setCellValue("EnderecoMae");
        row.createCell((short) 16).setCellValue("TelefoneCelularMae");
        row.createCell((short) 17).setCellValue("TelefoneResidencialMae");
        row.createCell((short) 18).setCellValue("TelefoneComercialMae");
        row.createCell((short) 19).setCellValue("emailMae");

        List<AlunoVariavel> list = new AlunoVariavelService().listarRelatorioSecretaria(Tutoria, Ano, Periodo,
                Neces, Prog, Status);
        for (AlunoVariavel alunoVariavel : list) {
            h++;
            row = firstSheet.createRow(h);
            //row.createCell((short) 0).setCellValue("Relatrio");

            if (tut != "" && tut != null) {

                String valor = alunoVariavel.getGrupo().getTutoria().getTutoria();

                if (valor != null && valor != "-") {
                    retorno.add(valor);

                    row.createCell((short) 0).setCellValue(valor);
                } else {
                    retorno.add("no informado");
                }
            }

            if (Nome != "" && Nome != null) {

                String valor = alunoVariavel.getAluno().getNome();

                if (valor != null && valor != "-") {
                    retorno.add(valor);
                    row.createCell((short) 1).setCellValue(valor);

                } else {
                    retorno.add("no informado");
                }

            }
            if (Sexo != "" && Sexo != null) {

                String valor = alunoVariavel.getAluno().getSexo();

                if (valor != null && valor != "-") {
                    retorno.add(valor);
                    row.createCell((short) 2).setCellValue(valor);
                } else {
                    retorno.add("no informado");
                }

            }
            if (Datanascimento != "" && Datanascimento != null) {

                Date valor = alunoVariavel.getAluno().getDataNascimento();

                if (valor != null) {

                    DateFormat formatter = new SimpleDateFormat("dd-MM-yy");

                    String dataS = formatter.format(valor);

                    //Date data = (Date) formatter.parse(dataS);

                    retorno.add(dataS);

                    row.createCell((short) 3).setCellValue(valor);
                } else {
                    retorno.add(null);
                }

            }
            if (Endereco != "" && Endereco != null) {

                String valor = alunoVariavel.getAluno().getEndereco();

                if (valor != null && valor != "-") {
                    retorno.add(valor);
                    row.createCell((short) 4).setCellValue(valor);
                } else {
                    retorno.add("no informado");
                }

            }
            if (TelefoneResidencial != "" && TelefoneResidencial != null) {

                String valor = alunoVariavel.getAluno().getTelefoneResidencialResponsavel();

                if (valor != null && valor != "-") {
                    retorno.add(valor);
                    row.createCell((short) 5).setCellValue(valor);
                } else {
                    retorno.add("no informado");
                }

            }
            if (TelefoneCelular != "" && TelefoneCelular != null) {

                String valor = alunoVariavel.getAluno().getTelefoneCelularResponsavel();

                if (valor != null && valor != "-") {
                    retorno.add(valor);

                    row.createCell((short) 6).setCellValue(valor);
                } else {
                    retorno.add("no informado");
                }

            }
            if (email != "" && email != null) {

                String valor = alunoVariavel.getAluno().getEmail();

                if (valor != null && valor != "-") {
                    retorno.add(valor);

                    row.createCell((short) 7).setCellValue(valor);
                } else {
                    retorno.add("no informado");
                }

            }
            if (NomeResponsavel != "" && NomeResponsavel != null) {

                String valor = alunoVariavel.getAluno().getNomeResponsavel();

                if (valor != null && valor != "-") {
                    retorno.add(valor);

                    row.createCell((short) 8).setCellValue(valor);
                } else {
                    retorno.add("no informado");
                }

            }
            if (ParentescoResponsavel != "" && ParentescoResponsavel != null) {

                String valor = alunoVariavel.getAluno().getParentescoResponsavel();

                if (valor != null && valor != "-") {
                    retorno.add(valor);

                    row.createCell((short) 9).setCellValue(valor);
                } else {
                    retorno.add("no informado");
                }

            }
            if (TelefoneResidencialResponsavel != "" && TelefoneResidencialResponsavel != null) {

                String valor = alunoVariavel.getAluno().getTelefoneResidencialResponsavel();

                if (valor != null && valor != "-") {
                    retorno.add(valor);

                    row.createCell((short) 10).setCellValue(valor);
                } else {
                    retorno.add("no informado");
                }

            }
            if (TelefoneCelularResponsavel != "" && TelefoneCelularResponsavel != null) {

                String valor = alunoVariavel.getAluno().getTelefoneCelularResponsavel();

                if (valor != null && valor != "-") {
                    retorno.add(valor);

                    row.createCell((short) 11).setCellValue(valor);
                } else {
                    retorno.add("no informado");
                }

            }
            if (TelefoneComercialResponsavel != "" && TelefoneComercialResponsavel != null) {

                String valor = alunoVariavel.getAluno().getTelefoneComercialResponsavel();

                if (valor != null && valor != "-") {
                    retorno.add(valor);

                    row.createCell((short) 12).setCellValue(valor);
                } else {
                    retorno.add("no informado");
                }

            }
            if (emailResponsavel != "" && emailResponsavel != null) {

                String valor = alunoVariavel.getAluno().getEmail1Responsavel();

                if (valor != null && valor != "-") {
                    retorno.add(valor);

                    row.createCell((short) 13).setCellValue(valor);
                } else {
                    retorno.add("no informado");
                }

            }
            if (NomeMae != "" && NomeMae != null) {

                String valor = alunoVariavel.getAluno().getNomeMae();

                if (valor != null && valor != "-") {
                    retorno.add(valor);

                    row.createCell((short) 14).setCellValue(valor);
                } else {
                    retorno.add("no informado");
                }

            }
            if (EnderecoMae != "" && EnderecoMae != null) {

                String valor = alunoVariavel.getAluno().getEnderecoMae();

                if (valor != null && valor != "-") {
                    retorno.add(valor);

                    row.createCell((short) 15).setCellValue(valor);
                } else {
                    retorno.add("no informado");
                }

            }
            if (TelefoneCelularMae != "" && TelefoneCelularMae != null) {

                String valor = alunoVariavel.getAluno().getTelefoneCelularMae();

                if (valor != null && valor != "-") {
                    retorno.add(valor);

                    row.createCell((short) 16).setCellValue(valor);
                } else {
                    retorno.add("no informado");
                }

            }
            if (TelefoneResidencialMae != "" && TelefoneResidencialMae != null) {

                String valor = alunoVariavel.getAluno().getTelefoneResidencialMae();

                if (valor != null && valor != "-") {
                    retorno.add(valor);

                    row.createCell((short) 17).setCellValue(valor);
                } else {
                    retorno.add("no informado");
                }

            }
            if (TelefoneComercialMae != "" && TelefoneComercialMae != null) {

                String valor = alunoVariavel.getAluno().getTelefoneComercialMae();

                if (valor != null && valor != "-") {
                    retorno.add(valor);

                    row.createCell((short) 18).setCellValue(valor);
                } else {
                    retorno.add("no informado");
                }

            }
            if (emailMae != "" && emailMae != null) {

                String valor = alunoVariavel.getAluno().getEmail1Mae();

                if (valor != null && valor != "-") {
                    retorno.add(valor);

                    row.createCell((short) 19).setCellValue(valor);
                } else {
                    retorno.add("no informado");
                }
            }

            listRetorno.add(retorno);
        }

        if (listRetorno.isEmpty()) {
            retorno.add("no h valores");
            listRetorno.add(retorno);
        }

        workbook.write(fos);

        retorno.add("http://177.55.99.90/files/" + nomeArquivo);
        //retorno.add("http://172.16.31.178/"+nomeArquivo);
        listRetorno.add(retorno);
        return listRetorno.get(0);

    } catch (Exception e) {
        e.printStackTrace();
        logger.info("Erro ao exportar arquivo");

    } finally {
        try {
            fos.flush();
            fos.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    return null;

}

From source file:br.com.pontocontrol.controleponto.controller.impl.ExportadorXLSController.java

@Override
public boolean extrair(FolhaMensalPonto folhaMensal, String outputFileDir) {
    Calendar data = Calendar.getInstance();
    data.set(Calendar.MONTH, folhaMensal.getMes());
    data.set(Calendar.YEAR, folhaMensal.getAno());
    final String nomeArquivo = format("%s-%s_%s.xls",
            SessaoManager.getInstance().getUsuarioAutenticado().getLogin(),
            formatDate("yyyy-MMMM", data.getTime()), formatDate("yyyyMMddHHmmssSSS", new Date()));
    final String filePath = format("%s/%s", outputFileDir, nomeArquivo);
    File arquivoXLS = new File(filePath);
    FileOutputStream fos = null;/*w w  w  . ja va2s.  c om*/
    try {
        arquivoXLS.createNewFile();

        fos = new FileOutputStream(arquivoXLS);

        HSSFWorkbook workbook = HSSFWorkbook.create(InternalWorkbook.createWorkbook());

        final String nomePlanilha = formatDate("MMM-yy", data.getTime());
        HSSFSheet planilha = workbook.createSheet(nomePlanilha);

        //TOTAL ROW
        HSSFRow totalRow = planilha.createRow(0);
        totalRow.createCell(CELL_INDEX.TOTAL_ROW.TOTAL_TXT).setCellValue("Total:");
        totalRow.createCell(CELL_INDEX.TOTAL_ROW.TOTAL_VALUE).setCellValue(folhaMensal.calcularTotalMensal());
        totalRow.createCell(CELL_INDEX.TOTAL_ROW.VAR_TXT).setCellValue("Variao:");
        totalRow.createCell(CELL_INDEX.TOTAL_ROW.VAR_VALUE).setCellValue(folhaMensal.calcularVariacaoMensal());

        //HEADER
        HSSFRow headerRow = planilha.createRow(1);
        headerRow.createCell(CELL_INDEX.DIA).setCellValue("Dia");
        headerRow.createCell(CELL_INDEX.ENTRADA).setCellValue("Entrada");
        headerRow.createCell(CELL_INDEX.ALMOCO).setCellValue("Almoo");
        headerRow.createCell(CELL_INDEX.RETORNO).setCellValue("Retorno");
        headerRow.createCell(CELL_INDEX.SAIDA).setCellValue("Sada");
        headerRow.createCell(CELL_INDEX.TOTAL_EXP).setCellValue("Expediente");
        headerRow.createCell(CELL_INDEX.VARIACAO).setCellValue("Variao");

        formatHeaderRow(workbook, headerRow);
        Calendar cal = Calendar.getInstance();
        cal.set(Calendar.YEAR, folhaMensal.getAno());
        cal.set(Calendar.MONTH, folhaMensal.getMes());

        for (int dia = 1; dia <= cal.getActualMaximum(Calendar.DAY_OF_MONTH); dia++) {
            int i = planilha.getPhysicalNumberOfRows();
            HSSFRow row = planilha.createRow(i);
            cal.set(Calendar.DAY_OF_MONTH, dia);
            row.createCell(CELL_INDEX.DIA).setCellValue(formatDate("MMM dd, EEE", cal.getTime()));

            RegistroDiarioPonto reg = folhaMensal.getRegistros().get(dia);
            if (reg != null) {
                row.createCell(CELL_INDEX.ENTRADA)
                        .setCellValue(reg.getEntrada() != null ? reg.getEntrada().format(TIME_FORMATTER) : "");
                row.createCell(CELL_INDEX.ALMOCO)
                        .setCellValue(reg.getAlmoco() != null ? reg.getAlmoco().format(TIME_FORMATTER) : "");
                row.createCell(CELL_INDEX.RETORNO)
                        .setCellValue(reg.getRetorno() != null ? reg.getRetorno().format(TIME_FORMATTER) : "");
                row.createCell(CELL_INDEX.SAIDA)
                        .setCellValue(reg.getSaida() != null ? reg.getSaida().format(TIME_FORMATTER) : "");
                row.createCell(CELL_INDEX.TOTAL_EXP).setCellValue(
                        reg.isRegistroDiarioCompleto() ? reg.calcularTotalExpedienteAsNumber() : 0);
                row.createCell(CELL_INDEX.VARIACAO)
                        .setCellValue(reg.isRegistroDiarioCompleto() ? reg.calcularVariacaoExpediente() : 0);
            } else {
                row.createCell(CELL_INDEX.ENTRADA).setCellValue("");
                row.createCell(CELL_INDEX.ALMOCO).setCellValue("");
                row.createCell(CELL_INDEX.RETORNO).setCellValue("");
                row.createCell(CELL_INDEX.SAIDA).setCellValue("");
                row.createCell(CELL_INDEX.TOTAL_EXP).setCellValue("");
                row.createCell(CELL_INDEX.VARIACAO).setCellValue("");
            }
            if (SessaoManager.getInstance().getUsuarioAutenticado().checarSeDiaExpediente(cal)) {
                formatRow(workbook, row);
            } else {
                formatHeaderRow(workbook, row);
            }
        }
        for (int i = 0; i < headerRow.getPhysicalNumberOfCells(); i++) {
            planilha.autoSizeColumn(i);
        }
        workbook.write(fos);
        fos.flush();
        return true;
    } catch (IOException ex) {
        LOG.log(Level.SEVERE, "Erro ao criar arquivo XLS de sada", ex);
        return false;
    } finally {
        IOUtils.closeQuietly(fos);
    }
}

From source file:br.edu.tglima.model.result.PlanilhaXLS.java

License:Open Source License

/**
 * Mtodo responsvel por gerar a planilha XLS.
 * /*www  . j a v a 2s . c o m*/
 * 
 * @param arquivo Referente ao local e nome do arquivo.
 * @return Retorno do tipo Boolean, indicando se o arquivo foi gerado
 * com sucesso, ou no.
 */
public boolean gerarPlanilha(File arquivo) {

    try {

        /*Verificamos se j existe um arquivo com esse "nome".
        Caso ele exista, ele ser removido e o novo arquivo ser gerado.*/
        if (workbook.getNumberOfSheets() > 0) {
            workbook.removeSheetAt(0);
        }

        HSSFSheet sheet = workbook.createSheet("Valores Exportados");

        /*         Criando as linhas. --------------------------------------------- */

        HSSFRow header1 = sheet.createRow((short) 0);
        HSSFRow linha02 = sheet.createRow((short) 1);
        HSSFRow linha03 = sheet.createRow((short) 2);
        HSSFRow linha04 = sheet.createRow((short) 3);
        HSSFRow linha05 = sheet.createRow((short) 4);

        HSSFRow header2 = sheet.createRow((short) 7);
        HSSFRow linha09 = sheet.createRow((short) 8);
        HSSFRow linha10 = sheet.createRow((short) 9);
        HSSFRow linha11 = sheet.createRow((short) 10);
        HSSFRow linha12 = sheet.createRow((short) 11);
        HSSFRow linha13 = sheet.createRow((short) 12);
        HSSFRow linha14 = sheet.createRow((short) 13);
        HSSFRow linha15 = sheet.createRow((short) 14);
        HSSFRow linha17 = sheet.createRow((short) 16);

        HSSFRow header3 = sheet.createRow((short) 19);
        HSSFRow linha21 = sheet.createRow((short) 20);
        HSSFRow linha22 = sheet.createRow((short) 21);
        HSSFRow linha23 = sheet.createRow((short) 22);
        HSSFRow linha25 = sheet.createRow((short) 24);

        //  ------------------------------------------------------------------------ //

        /*         Mesclando as clulas. ------------------------------------------ */

        sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 2));
        sheet.addMergedRegion(new CellRangeAddress(7, 7, 0, 2));
        sheet.addMergedRegion(new CellRangeAddress(19, 19, 0, 2));

        //  ------------------------------------------------------------------------ //

        /*         Definindo a largura das colunas. ------------------------------- */

        sheet.setColumnWidth(0, 12000);
        sheet.setColumnWidth(1, 5200);
        sheet.setColumnWidth(2, 6500);

        //  ------------------------------------------------------------------------ //

        /*         Definindo os estilos das clulas. ------------------------------ */

        CellStyle headerStyle = workbook.createCellStyle();
        Font headerFont = workbook.createFont();
        headerFont.setFontHeightInPoints((short) 20);
        headerStyle.setFont(headerFont);
        headerStyle.setAlignment(HorizontalAlignment.CENTER);

        CellStyle cellCentered = workbook.createCellStyle();
        cellCentered.setAlignment(HorizontalAlignment.CENTER);

        CellStyle cellFontBold = workbook.createCellStyle();
        Font fontBold = workbook.createFont();
        fontBold.setBold(true);
        cellFontBold.setFont(fontBold);

        CellStyle cellResulted = workbook.createCellStyle();
        Font resultFont = workbook.createFont();
        resultFont.setBold(true);
        cellResulted.setFont(resultFont);
        cellResulted.setAlignment(HorizontalAlignment.CENTER);

        Cell cell;

        //  ------------------------------------------------------------------------ //

        /*         Criando as Colunas da Tabela ----------------------------------- */

        //Colunas da linha 1
        header1.createCell(0).setCellValue("Dados Fornecidos");

        //Colunas da linha 2
        linha02.createCell(0).setCellValue("Data de Entrada");
        linha02.createCell(2).setCellValue(this.rst.getDataEntrada());

        //Colunas da Linha 3
        linha03.createCell(0).setCellValue("Data de Sada");
        linha03.createCell(2).setCellValue(this.rst.getDataSaida());

        //Colunas da Linha 4
        linha04.createCell(0).setCellValue("Salrio Informado");
        linha04.createCell(2).setCellValue(this.rst.getSalario());

        //Colunas da Linha 5
        linha05.createCell(0).setCellValue("Motivo da Sada");
        linha05.createCell(2).setCellValue(this.rst.getMotivoRes());

        //Colunas da linha 8
        header2.createCell(0).setCellValue("Resciso");

        //Colunas da linha 9
        linha09.createCell(0).setCellValue("Item");
        linha09.createCell(1).setCellValue("Referncia");
        linha09.createCell(2).setCellValue("Valor");

        //Colunas da Linha 10
        linha10.createCell(0).setCellValue("Saldo Salrio");
        linha10.createCell(1).setCellValue(this.rst.getTotDiasTrabUltMes());
        linha10.createCell(2).setCellValue(this.rst.getUltSalario());

        //Colunas da Linha 11
        linha11.createCell(0).setCellValue("13 Proporcional");
        linha11.createCell(1).setCellValue(this.rst.getTotMesesTrabUltAno());
        linha11.createCell(2).setCellValue(this.rst.getVlrDecimo());

        //Colunas da Linha 12
        linha12.createCell(0).setCellValue("Frias Proporcional");
        linha12.createCell(1).setCellValue(this.rst.getTotMesesAqFerias());
        linha12.createCell(2).setCellValue(this.rst.getVlrFerias());

        //Colunas da Linha 13
        linha13.createCell(0).setCellValue("1/3 Frias Proporcional");
        linha13.createCell(1).setCellValue("-");
        linha13.createCell(2).setCellValue(this.rst.getVlrTercoFerias());

        //Colunas da Linha 14
        linha14.createCell(0).setCellValue("Frias Vencidas");
        linha14.createCell(1).setCellValue(this.rst.getTotFeriasVenc());
        linha14.createCell(2).setCellValue(this.rst.getVlrFeriasVenc());

        //Colunas da linha 15
        linha15.createCell(0).setCellValue("Aviso Prvio");
        linha15.createCell(1).setCellValue(this.rst.getTotDiasAviso());
        linha15.createCell(2).setCellValue(this.rst.getVlrAvisoP());

        //Colunas da linha 17
        linha17.createCell(0).setCellValue("Valor Total");
        linha17.createCell(1).setCellValue("-");
        linha17.createCell(2).setCellValue(this.rst.getVlrTotVenc());

        //Colunas da Linha 20
        header3.createCell(0).setCellValue("FGTS");

        //Colunas da Linha 21
        linha21.createCell(0).setCellValue("Valores do FGTS estaro disponveis para saque?");
        linha21.createCell(2).setCellValue(this.rst.getReceberFgts());

        //Colunas da Linha 22
        linha22.createCell(0).setCellValue("Saldo FGTS");
        linha22.createCell(2).setCellValue(this.rst.getSaldoFgts());

        //Colunas da Linha 23
        linha23.createCell(0).setCellValue("Multa de 40%");
        linha23.createCell(2).setCellValue(this.rst.getVlrMulta());

        //Colunas da Linha 25
        linha25.createCell(0).setCellValue("Valor total");
        linha25.createCell(2).setCellValue(this.rst.getVlrTotFgts());

        //  ------------------------------------------------------------------------ //  

        /*         Aplicando os estilos nas clulas ------------------------------- */

        cell = header1.getCell(0);
        cell.setCellStyle(headerStyle);
        header1.setRowStyle(headerStyle);
        header1.setHeightInPoints(30);

        cell = header2.getCell(0);
        cell.setCellStyle(headerStyle);
        header2.setRowStyle(headerStyle);
        header2.setHeightInPoints(30);

        cell = header3.getCell(0);
        cell.setCellStyle(headerStyle);
        header3.setRowStyle(headerStyle);
        header3.setHeightInPoints(30);

        linha02.getCell(2).setCellStyle(cellCentered);

        linha03.getCell(2).setCellStyle(cellCentered);

        linha04.getCell(2).setCellStyle(cellCentered);

        linha05.getCell(2).setCellStyle(cellCentered);

        linha09.getCell(1).setCellStyle(cellCentered);
        linha09.getCell(2).setCellStyle(cellCentered);

        linha10.getCell(1).setCellStyle(cellCentered);
        linha10.getCell(2).setCellStyle(cellCentered);

        linha11.getCell(1).setCellStyle(cellCentered);
        linha11.getCell(2).setCellStyle(cellCentered);

        linha12.getCell(1).setCellStyle(cellCentered);
        linha12.getCell(2).setCellStyle(cellCentered);

        linha13.getCell(1).setCellStyle(cellCentered);
        linha13.getCell(2).setCellStyle(cellCentered);

        linha14.getCell(1).setCellStyle(cellCentered);
        linha14.getCell(2).setCellStyle(cellCentered);

        linha15.getCell(1).setCellStyle(cellCentered);
        linha15.getCell(2).setCellStyle(cellCentered);

        linha17.getCell(0).setCellStyle(cellFontBold);
        linha17.getCell(1).setCellStyle(cellCentered);
        linha17.getCell(2).setCellStyle(cellResulted);

        linha21.getCell(2).setCellStyle(cellCentered);

        linha22.getCell(2).setCellStyle(cellCentered);

        linha23.getCell(2).setCellStyle(cellCentered);

        linha25.getCell(0).setCellStyle(cellFontBold);
        linha25.getCell(2).setCellStyle(cellResulted);

        //  ------------------------------------------------------------------------ //           

        /*         Escrever, salvar e fechar o arquivo ---------------------------- */

        workbook.write(arquivo); // Escrevendo no arquivo.

        workbook.close(); // Salvando e fechando o arquivo.

        return true;

    } catch (Exception e) {

        System.err.println("No foi possvel gerar seu arquivo!" + " \n" + e.getLocalizedMessage());

        return false;

    }

}

From source file:br.prof.salesfilho.oci.service.ExcelService.java

public void createSheet(String name, List<ClassificationResult> classificationResults) {
    HSSFSheet sheet = workbook.createSheet(name);

    HSSFRow rowhead = sheet.createRow((short) 0);
    rowhead.createCell(0).setCellValue("fileName");
    rowhead.createCell(1).setCellValue("finalClassification");
    rowhead.createCell(2).setCellValue("date");
    rowhead.createCell(3).setCellValue("nudeAvgScore");
    rowhead.createCell(4).setCellValue("notNudeAvgScore");
    rowhead.createCell(5).setCellValue("maybeNudeAvgScore");
    rowhead.createCell(6).setCellValue("kernelSize");
    rowhead.createCell(7).setCellValue("executionTime");
    rowhead.createCell(8).setCellValue("classificationLevel");

    int idx = 1;/*from  ww w  .j a v  a 2  s.  c  o  m*/
    for (ClassificationResult classificationResult : classificationResults) {
        HSSFRow row = sheet.createRow((short) idx);
        row.createCell(0).setCellValue(classificationResult.getFileName());
        row.createCell(1).setCellValue(classificationResult.getFinalClassification());
        row.createCell(2).setCellValue(classificationResult.getDate());
        row.createCell(3).setCellValue(classificationResult.getNudeAvgScore());
        row.createCell(4).setCellValue(classificationResult.getNotNudeAvgScore());
        row.createCell(5).setCellValue(classificationResult.getMaybeNudeAvgScore());
        row.createCell(6).setCellValue(classificationResult.getKernelSize());
        row.createCell(7).setCellValue(classificationResult.getExecutionTime());
        row.createCell(8).setCellValue(classificationResult.getClassificationLevel());

        idx++;
    }
}