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:BaseDatos.ExportarDatos.java

private void CrearExelCompras() {
    FileOutputStream archivoSalida = null;

    try {//from  w w  w .  j av  a 2 s  . co m
        Statement conexion = ConectarMysql.obtenerConexion().createStatement(ResultSet.CONCUR_READ_ONLY,
                ResultSet.TYPE_FORWARD_ONLY);
        HSSFWorkbook libro = new HSSFWorkbook();
        HSSFSheet hoja = libro.createSheet("reporte");
        String SqlVentas = "select * from logCompras";
        ResultSet resultado = conexion.executeQuery(SqlVentas);

        HSSFRow fila = hoja.createRow((short) 0);
        HSSFCell celda = fila.createCell(0);
        celda.setCellValue("nombre del producto");
        celda = fila.createCell(1);
        celda.setCellValue("fabricante");
        celda = fila.createCell(2);
        celda.setCellValue("contenedor");
        celda = fila.createCell(3);
        celda.setCellValue("cantidad");
        celda = fila.createCell(4);
        celda.setCellValue("precio Compra");
        celda = fila.createCell(5);
        celda.setCellValue("precio Venta");
        celda = fila.createCell(6);
        celda.setCellValue("fecha");
        if (resultado.first()) {
            int contador = 1;

            do {
                filaExel.clear();
                fila = hoja.createRow((short) contador);

                obtenerDatos(resultado.getInt(2));
                cantidad = resultado.getString(3);
                precioCompra = resultado.getString(4);
                precioVenta = resultado.getString(5);
                fecha = resultado.getString(6);
                filaExel.add(nombreProducto);
                filaExel.add(fabricante);
                filaExel.add(contenedor);
                filaExel.add(cantidad);
                filaExel.add(precioCompra);
                filaExel.add(precioVenta);
                filaExel.add(fecha);
                for (int a = 0; a < filaExel.size(); a++) {
                    celda = fila.createCell(a);
                    if (a == 3) {
                        celda.setCellValue(Integer.parseInt(filaExel.get(a)));
                    } else if (a == 4 || a == 5) {
                        celda.setCellValue(Double.parseDouble(filaExel.get(a)));
                    } else {
                        celda.setCellValue(filaExel.get(a));
                    }
                }
                this.operacion.setText("operando : " + contador);
                contador++;
            } while (resultado.next());

        }
        String direccionCompleta = "C:\\Users\\zombozo\\Documents\\compras.xls";
        File archivo = new File(direccionCompleta);
        archivoSalida = new FileOutputStream(archivo);
        libro.write(archivoSalida);
        archivoSalida.close();
        JOptionPane.showMessageDialog(rootPane,
                "Creado Correctamente, busque el archivo en la carpeta documentos");
        conexion.close();
    } catch (Exception e) {
        JOptionPane.showMessageDialog(rootPane, "Ocurrio un error 1: " + e);
    }
}

From source file:bd.gov.forms.web.FormBuilder.java

License:Open Source License

@RequestMapping(value = "/excelExport", method = RequestMethod.GET)
public String excelExport(@RequestParam(value = "formId", required = true) String formId,
        @RequestParam(value = "page", required = false) Integer page,
        @RequestParam(value = "colName", required = false) String colName,
        @RequestParam(value = "colVal", required = false) String colVal,
        @RequestParam(value = "sortCol", required = false) String sortCol,
        @RequestParam(value = "sortDir", required = false) String sortDir, ModelMap model,
        HttpServletResponse response, HttpServletRequest request) throws IOException {

    String access = UserAccessChecker.check(request);
    if (access != null) {
        return access;
    }// ww  w  .j a va2 s  . c  o m

    if (page == null) {
        page = 1;
    }

    Form form = formDao.getFormWithFields(formId);

    List<HashMap> list = formDao.getEntryList(form, page, colName, colVal, sortCol, sortDir, false);
    List<String> headers = getEntryListHeaders(form);

    response.setContentType("application/vnd.ms-excel");
    // TODO: file name

    HSSFWorkbook workbook = new HSSFWorkbook();
    HSSFSheet sheet = workbook.createSheet("Excel Report");

    int r = 0;
    HSSFRow row = sheet.createRow((short) r++);
    int count = 0;
    for (String header : headers) {
        HSSFCell cell = row.createCell(count++);
        cell.setCellValue(header);
    }

    for (HashMap hashmap : list) {
        row = sheet.createRow((short) r++);
        count = 0;

        HSSFCell cell = row.createCell(count++);
        cell.setCellValue((String) hashmap.get("entry_date"));

        cell = row.createCell(count++);
        cell.setCellValue((String) hashmap.get("entry_time"));

        cell = row.createCell(count++);
        cell.setCellValue((String) hashmap.get("entry_status"));

        for (Field field : form.getFields()) {
            cell = row.createCell(count++);
            cell.setCellValue((String) hashmap.get(field.getColName()));
        }
    }

    String fileName = "Report-" + formId + ".xls";
    response.setHeader("Content-Disposition", "inline; filename=" + fileName);
    response.setContentType("application/vnd.ms-excel");

    ServletOutputStream outputStream = response.getOutputStream();
    sheet.getWorkbook().write(outputStream);
    outputStream.flush();

    return null;
}

From source file:be.vds.jtbdive.client.view.core.dive.profile.DiveProfileExcelParser.java

License:Open Source License

public void export(Date date, DiveProfile diveProfile, File file) throws IOException {
    HSSFWorkbook wb = new HSSFWorkbook();
    HSSFSheet sheet = wb.createSheet(UIAgent.getInstance().getExportFormatDateHoursFull().format(date));

    HSSFCellStyle cellStyle = wb.createCellStyle();
    HSSFFont font = wb.createFont();/*  w  w  w  .ja v  a 2 s  .c o m*/
    font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
    cellStyle.setFont(font);

    int rowIndex = 0;
    int colIndex = 0;
    HSSFRow row = sheet.createRow(rowIndex++);
    HSSFCell cell = row.createCell(colIndex++);
    cell.setCellValue("Time (s)");
    cell.setCellStyle(cellStyle);

    cell = row.createCell(colIndex++);
    cell.setCellValue("Depth (m)");
    cell.setCellStyle(cellStyle);

    cell = row.createCell(colIndex++);
    cell.setCellValue("Ascent Warning");
    cell.setCellStyle(cellStyle);

    cell = row.createCell(colIndex++);
    cell.setCellValue("Bottom Time Warning");
    cell.setCellStyle(cellStyle);

    cell = row.createCell(colIndex++);
    cell.setCellValue("Deco Ceiling Warning");
    cell.setCellStyle(cellStyle);

    cell = row.createCell(colIndex++);
    cell.setCellValue("Deco Entry");
    cell.setCellStyle(cellStyle);

    Map<Double, Double> entries = diveProfile.getDepthEntries();
    List<Double> seconds = new ArrayList<Double>(entries.keySet());
    Collections.sort(seconds);
    for (Double time : seconds) {
        colIndex = 0;
        row = sheet.createRow(rowIndex++);
        row.createCell(colIndex++, HSSFCell.CELL_TYPE_NUMERIC).setCellValue(time);
        row.createCell(colIndex++, HSSFCell.CELL_TYPE_NUMERIC).setCellValue(entries.get(time));
        row.createCell(colIndex++, HSSFCell.CELL_TYPE_BOOLEAN)
                .setCellValue(diveProfile.getAscentWarnings().contains(time));
        row.createCell(colIndex++, HSSFCell.CELL_TYPE_BOOLEAN)
                .setCellValue(diveProfile.getRemainingBottomTimeWarnings().contains(time));
        row.createCell(colIndex++, HSSFCell.CELL_TYPE_BOOLEAN)
                .setCellValue(diveProfile.getDecoCeilingWarnings().contains(time));
        row.createCell(colIndex++, HSSFCell.CELL_TYPE_BOOLEAN)
                .setCellValue(diveProfile.getDecoEntries().contains(time));
    }

    for (int i = 0; i <= colIndex; i++) {
        sheet.autoSizeColumn(i);
    }

    FileOutputStream fileOut = new FileOutputStream(file);
    wb.write(fileOut);
    fileOut.close();
}

From source file:bean.BankProfileData.java

public void export0() {
    Integer columnNo;/*from  ww w.j  a  v  a2  s .co  m*/
    HSSFWorkbook workbook;
    HSSFSheet sheet;
    HSSFRow headerRow, dataRow, totalRow = null;
    HSSFCell cell;
    HSSFCellStyle cellStyle, boldStyle;
    HSSFFont font;

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

    getExportData().createFolder(null, themeDisplay, "Bank SL 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);

        for (int i = 0; i < getAccountsWithSubsidiaryData().getAccountCodesFiltered().size(); i++) {
            try {
                sheet = workbook.createSheet(getDataConvert()
                        .accountCodeConvert(getAccountsWithSubsidiaryData().getAccountCodesFiltered().get(i)));
            } catch (Exception e) {
                sheet = workbook.createSheet(getAccountsWithSubsidiaryData().getAccountCodesFiltered().get(i));
            }

            headerRow = sheet.createRow((short) 0);
            columnNo = 0;
            cell = headerRow.createCell(columnNo++);
            cell.setCellValue(getDataConvert()
                    .accountCodeConvert(getAccountsWithSubsidiaryData().getAccountCodesFiltered().get(i)));
            cell.setCellStyle(boldStyle);

            try {
                headerRow = sheet.createRow(headerRow.getRowNum() + 1);
                columnNo = 0;
                cell = headerRow.createCell(columnNo++);
                cell.setCellValue("As of " + getCustomDate()
                        .formatDate(getAccountsWithSubsidiaryData().getReportDate(), "MM-dd-YYYY"));
                cell.setCellStyle(boldStyle);
            } catch (Exception e) {
                getAccountsWithSubsidiaryData().setReportDate(getCustomDate().getCurrentDate());

                cell.setCellValue("As of " + getCustomDate()
                        .formatDate(getAccountsWithSubsidiaryData().getReportDate(), "MM-dd-YYYY"));
                cell.setCellStyle(boldStyle);
            }

            if (getAccountsWithSubsidiaryData().getAcctCreateDateFrom() != null
                    || getAccountsWithSubsidiaryData().getAcctCreateDateTo() != null) {
                headerRow = sheet.createRow(headerRow.getRowNum() + 1);
                columnNo = 0;
                cell = headerRow.createCell(columnNo++);
                cell.setCellValue(getAccountsWithSubsidiaryData().getAcctCreateDateTo() != null
                        ? "Account Created Date: " + getCustomDate()
                                .formatDate(
                                        getAccountsWithSubsidiaryData().getAcctCreateDateFrom(), "MM-dd-YYYY")
                                .concat(" - ")
                                .concat(getCustomDate().formatDate(
                                        getAccountsWithSubsidiaryData().getAcctCreateDateTo(), "MM-dd-YYYY"))
                        : "Account Created Date: " + getCustomDate().formatDate(
                                getAccountsWithSubsidiaryData().getAcctCreateDateFrom(), "MM-dd-YYYY"));
                cell.setCellStyle(boldStyle);
            }

            if ((getAccountsWithSubsidiaryData().getAmountFilter() != null
                    && getAccountsWithSubsidiaryData().getAmountFilter().compareTo(BigDecimal.ZERO) == 1)) {
                headerRow = sheet.createRow(headerRow.getRowNum() + 1);
                columnNo = 0;
                cell = headerRow.createCell(columnNo++);
                cell.setCellValue("Amount Range: " + getDataConvert()
                        .numericConvert(getAccountsWithSubsidiaryData().getAmountFilter().doubleValue()));
                cell.setCellStyle(boldStyle);
            }

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

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

            cell = headerRow.createCell(columnNo++);
            cell.setCellValue("Name");
            cell.setCellStyle(boldStyle);

            cell = headerRow.createCell(columnNo++);
            cell.setCellValue("Account Status");
            cell.setCellStyle(boldStyle);

            cell = headerRow.createCell(columnNo++);
            cell.setCellValue("Balance");
            cell.setCellStyle(boldStyle);

            for (int ii = 0; ii < getBankProfileSummary().get(i).size(); ii++) {
                columnNo = 0;

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

                dataRow.createCell(columnNo++)
                        .setCellValue(getBankProfileSummary().get(i).get(ii)[2].toString());
                dataRow.createCell(columnNo++)
                        .setCellValue(getBankProfileSummary().get(i).get(ii)[4].toString());
                dataRow.createCell(columnNo++).setCellValue(getDataConvert()
                        .acctStatusConvert(getBankProfileSummary().get(i).get(ii)[6].toString().charAt(0)));

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

                totalRow = sheet.createRow((short) dataRow.getRowNum() + 2);
            }
            if (getBankProfileSummary().get(i).size() > 0) {
                cell = totalRow.createCell(1);
                cell.setCellValue("TOTAL");
                cell.setCellStyle(boldStyle);

                cell = totalRow.createCell(2);
                cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC);
                cell.setCellValue(getAccountsWithSubsidiaryData().getSubtotal().get(i).doubleValue());
                cell.setCellStyle(cellStyle);
            }
        }

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

        getExportData().fileUploadByDL(getExportData().getFilename(), "Bank SL Report", themeDisplay, null);

        File file = new File(getExportData().getFilename());
        if (file.exists()) {
            file.delete();
        }
    } catch (Exception e) {
        System.out.print("bankProfileData().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.ClassCaData.java

public void export0() {
    Integer columnNo;//w  ww.j  a  v a2s  .  c om
    HSSFWorkbook workbook;
    HSSFSheet sheet;
    HSSFRow headerRow, dataRow, totalRow = null;
    HSSFCell cell;
    HSSFCellStyle cellStyle, boldStyle;
    HSSFFont font;

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

    getExportData().createFolder(null, themeDisplay, "Advances 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);

        for (int i = 0; i < getAccountsWithSubsidiaryData().getAccountCodesFiltered().size(); i++) {
            try {
                sheet = workbook.createSheet(getDataConvert()
                        .accountCodeConvert(getAccountsWithSubsidiaryData().getAccountCodesFiltered().get(i)));
            } catch (Exception e) {
                sheet = workbook.createSheet(getAccountsWithSubsidiaryData().getAccountCodesFiltered().get(i));
            }

            headerRow = sheet.createRow((short) 0);
            columnNo = 0;
            cell = headerRow.createCell(columnNo++);
            cell.setCellValue(getDataConvert()
                    .accountCodeConvert(getAccountsWithSubsidiaryData().getAccountCodesFiltered().get(i)));
            cell.setCellStyle(boldStyle);

            try {
                headerRow = sheet.createRow(headerRow.getRowNum() + 1);
                columnNo = 0;
                cell = headerRow.createCell(columnNo++);
                cell.setCellValue("As of " + getCustomDate()
                        .formatDate(getAccountsWithSubsidiaryData().getReportDate(), "yyyy-MM-dd"));
                cell.setCellStyle(boldStyle);
            } catch (Exception e) {
                getAccountsWithSubsidiaryData().setReportDate(getCustomDate().getCurrentDate());

                cell.setCellValue("As of " + getCustomDate()
                        .formatDate(getAccountsWithSubsidiaryData().getReportDate(), "yyyy-MM-dd"));
                cell.setCellStyle(boldStyle);
            }

            if (getAccountsWithSubsidiaryData().getAcctCreateDateFrom() != null
                    || getAccountsWithSubsidiaryData().getAcctCreateDateTo() != null) {
                headerRow = sheet.createRow(headerRow.getRowNum() + 1);
                columnNo = 0;
                cell = headerRow.createCell(columnNo++);
                cell.setCellValue(
                        "Account Created Date " + getAccountsWithSubsidiaryData().getAcctCreateDateTo() != null
                                ? getCustomDate()
                                        .formatDate(getAccountsWithSubsidiaryData().getAcctCreateDateFrom(),
                                                "yyyy-MM-dd")
                                        .concat("-")
                                        .concat(getCustomDate().formatDate(
                                                getAccountsWithSubsidiaryData().getAcctCreateDateTo(),
                                                "yyyy-MM-dd"))
                                : getCustomDate().formatDate(
                                        getAccountsWithSubsidiaryData().getAcctCreateDateFrom(), "yyyy-MM-dd"));
                cell.setCellStyle(boldStyle);
            }

            if ((getAccountsWithSubsidiaryData().getAmountFilter() != null
                    && getAccountsWithSubsidiaryData().getAmountFilter().compareTo(BigDecimal.ZERO) == 1)) {
                headerRow = sheet.createRow(headerRow.getRowNum() + 1);
                columnNo = 0;
                cell = headerRow.createCell(columnNo++);
                cell.setCellValue("Amount Range: " + getDataConvert()
                        .numericConvert(getAccountsWithSubsidiaryData().getAmountFilter().doubleValue()));
                cell.setCellStyle(boldStyle);
            }

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

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

            cell = headerRow.createCell(columnNo++);
            cell.setCellValue("Name");
            cell.setCellStyle(boldStyle);

            cell = headerRow.createCell(columnNo++);
            cell.setCellValue("Account Status");
            cell.setCellStyle(boldStyle);

            cell = headerRow.createCell(columnNo++);
            cell.setCellValue("Balance");
            cell.setCellStyle(boldStyle);

            for (int ii = 0; ii < getClassCaSummary().get(i).size(); ii++) {
                columnNo = 0;

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

                dataRow.createCell(columnNo++).setCellValue(getClassCaSummary().get(i).get(ii)[2].toString());
                dataRow.createCell(columnNo++).setCellValue(getClassCaSummary().get(i).get(ii)[4].toString());
                dataRow.createCell(columnNo++).setCellValue(getDataConvert()
                        .acctStatusConvert(getClassCaSummary().get(i).get(ii)[6].toString().charAt(0)));

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

                totalRow = sheet.createRow((short) dataRow.getRowNum() + 2);
            }
            if (getClassCaSummary().get(i).size() > 0) {
                cell = totalRow.createCell(1);
                cell.setCellValue("TOTAL");
                cell.setCellStyle(boldStyle);

                cell = totalRow.createCell(2);
                cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC);
                cell.setCellValue(getAccountsWithSubsidiaryData().getSubtotal().get(i).doubleValue());
                cell.setCellStyle(cellStyle);
            }
        }

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

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

        File file = new File(getExportData().getFilename());
        if (file.exists()) {
            file.delete();
        }
    } catch (Exception e) {
        System.out.print("classCaData().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.ClassDmData0.java

public void export0() {
    Integer columnNo;/* w  ww .j a  v a 2 s .  c  o m*/
    HSSFWorkbook workbook;
    HSSFSheet sheet;
    HSSFRow headerRow, dataRow, totalRow = null;
    HSSFCell cell;
    HSSFCellStyle cellStyle, boldStyle;
    HSSFFont font;

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

    getExportData().createFolder(null, themeDisplay, "Planong Damayan 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);

        for (int i = 0; i < getAccountsWithSubsidiaryData().getAccountCodesFiltered().size(); i++) {
            try {
                sheet = workbook.createSheet(getDataConvert()
                        .accountCodeConvert(getAccountsWithSubsidiaryData().getAccountCodesFiltered().get(i)));
            } catch (Exception e) {
                sheet = workbook.createSheet(getAccountsWithSubsidiaryData().getAccountCodesFiltered().get(i));
            }

            headerRow = sheet.createRow((short) 0);
            columnNo = 0;
            cell = headerRow.createCell(columnNo++);
            cell.setCellValue(getDataConvert()
                    .accountCodeConvert(getAccountsWithSubsidiaryData().getAccountCodesFiltered().get(i)));
            cell.setCellStyle(boldStyle);

            try {
                headerRow = sheet.createRow(headerRow.getRowNum() + 1);
                columnNo = 0;
                cell = headerRow.createCell(columnNo++);
                cell.setCellValue("As of " + getCustomDate()
                        .formatDate(getAccountsWithSubsidiaryData().getReportDate(), "MM-dd-YYYY"));
                cell.setCellStyle(boldStyle);
            } catch (Exception e) {
                getAccountsWithSubsidiaryData().setReportDate(getCustomDate().getCurrentDate());

                cell.setCellValue("As of " + getCustomDate()
                        .formatDate(getAccountsWithSubsidiaryData().getReportDate(), "MM-dd-YYYY"));
                cell.setCellStyle(boldStyle);
            }

            if (getAccountsWithSubsidiaryData().getAcctCreateDateFrom() != null
                    || getAccountsWithSubsidiaryData().getAcctCreateDateTo() != null) {
                headerRow = sheet.createRow(headerRow.getRowNum() + 1);
                columnNo = 0;
                cell = headerRow.createCell(columnNo++);
                cell.setCellValue(getAccountsWithSubsidiaryData().getAcctCreateDateTo() != null
                        ? "Account Created Date: " + getCustomDate()
                                .formatDate(
                                        getAccountsWithSubsidiaryData().getAcctCreateDateFrom(), "MM-dd-YYYY")
                                .concat(" - ")
                                .concat(getCustomDate().formatDate(
                                        getAccountsWithSubsidiaryData().getAcctCreateDateTo(), "MM-dd-YYYY"))
                        : "Account Created Date: " + getCustomDate().formatDate(
                                getAccountsWithSubsidiaryData().getAcctCreateDateFrom(), "MM-dd-YYYY"));
                cell.setCellStyle(boldStyle);
            }

            if ((getAccountsWithSubsidiaryData().getAmountFilter() != null
                    && getAccountsWithSubsidiaryData().getAmountFilter().compareTo(BigDecimal.ZERO) == 1)) {
                headerRow = sheet.createRow(headerRow.getRowNum() + 1);
                columnNo = 0;
                cell = headerRow.createCell(columnNo++);
                cell.setCellValue("Amount Range: " + getDataConvert()
                        .numericConvert(getAccountsWithSubsidiaryData().getAmountFilter().doubleValue()));
                cell.setCellStyle(boldStyle);
            }

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

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

            cell = headerRow.createCell(columnNo++);
            cell.setCellValue("Name");
            cell.setCellStyle(boldStyle);

            cell = headerRow.createCell(columnNo++);
            cell.setCellValue("Account Status");
            cell.setCellStyle(boldStyle);

            cell = headerRow.createCell(columnNo++);
            cell.setCellValue("Balance");
            cell.setCellStyle(boldStyle);

            for (int ii = 0; ii < getClassDmSummary().get(i).size(); ii++) {
                columnNo = 0;

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

                dataRow.createCell(columnNo++).setCellValue(getClassDmSummary().get(i).get(ii)[2].toString());
                dataRow.createCell(columnNo++).setCellValue(getClassDmSummary().get(i).get(ii)[4].toString());
                dataRow.createCell(columnNo++).setCellValue(getDataConvert()
                        .acctStatusConvert(getClassDmSummary().get(i).get(ii)[6].toString().charAt(0)));

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

                totalRow = sheet.createRow((short) dataRow.getRowNum() + 2);
            }
            if (getClassDmSummary().get(i).size() > 0) {
                cell = totalRow.createCell(1);
                cell.setCellValue("TOTAL");
                cell.setCellStyle(boldStyle);

                cell = totalRow.createCell(2);
                cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC);
                cell.setCellValue(getAccountsWithSubsidiaryData().getSubtotal().get(i).doubleValue());
                cell.setCellStyle(cellStyle);
            }
        }

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

        getExportData().fileUploadByDL(getExportData().getFilename(), "Planong Damayan Report", themeDisplay,
                null);

        File file = new File(getExportData().getFilename());
        if (file.exists()) {
            file.delete();
        }
    } catch (Exception e) {
        System.out.print("classDmData0().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.ClassOpData.java

public void export0() {
    Integer columnNo;/*  w ww .  j a  v a  2  s. c o m*/
    HSSFWorkbook workbook;
    HSSFSheet sheet;
    HSSFRow headerRow, dataRow, totalRow = null;
    HSSFCell cell;
    HSSFCellStyle cellStyle, boldStyle;
    HSSFFont font;

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

    getExportData().createFolder(null, themeDisplay, "Other Current Liabilities 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);

        for (int i = 0; i < getAccountsWithSubsidiaryData().getAccountCodesFiltered().size(); i++) {
            try {
                sheet = workbook.createSheet(getDataConvert()
                        .accountCodeConvert(getAccountsWithSubsidiaryData().getAccountCodesFiltered().get(i)));
            } catch (Exception e) {
                sheet = workbook.createSheet(getAccountsWithSubsidiaryData().getAccountCodesFiltered().get(i));
            }

            headerRow = sheet.createRow((short) 0);
            columnNo = 0;
            cell = headerRow.createCell(columnNo++);
            cell.setCellValue(getDataConvert()
                    .accountCodeConvert(getAccountsWithSubsidiaryData().getAccountCodesFiltered().get(i)));
            cell.setCellStyle(boldStyle);

            try {
                headerRow = sheet.createRow(headerRow.getRowNum() + 1);
                columnNo = 0;
                cell = headerRow.createCell(columnNo++);
                cell.setCellValue("As of " + getCustomDate()
                        .formatDate(getAccountsWithSubsidiaryData().getReportDate(), "MM-dd-YYYY"));
                cell.setCellStyle(boldStyle);
            } catch (Exception e) {
                getAccountsWithSubsidiaryData().setReportDate(getCustomDate().getCurrentDate());

                cell.setCellValue("As of " + getCustomDate()
                        .formatDate(getAccountsWithSubsidiaryData().getReportDate(), "MM-dd-YYYY"));
                cell.setCellStyle(boldStyle);
            }

            if (getAccountsWithSubsidiaryData().getAcctCreateDateFrom() != null
                    || getAccountsWithSubsidiaryData().getAcctCreateDateTo() != null) {
                headerRow = sheet.createRow(headerRow.getRowNum() + 1);
                columnNo = 0;
                cell = headerRow.createCell(columnNo++);
                cell.setCellValue(getAccountsWithSubsidiaryData().getAcctCreateDateTo() != null
                        ? "Account Created Date: " + getCustomDate()
                                .formatDate(
                                        getAccountsWithSubsidiaryData().getAcctCreateDateFrom(), "MM-dd-YYYY")
                                .concat(" - ")
                                .concat(getCustomDate().formatDate(
                                        getAccountsWithSubsidiaryData().getAcctCreateDateTo(), "MM-dd-YYYY"))
                        : "Account Created Date: " + getCustomDate().formatDate(
                                getAccountsWithSubsidiaryData().getAcctCreateDateFrom(), "MM-dd-YYYY"));
                cell.setCellStyle(boldStyle);
            }

            if ((getAccountsWithSubsidiaryData().getAmountFilter() != null
                    && getAccountsWithSubsidiaryData().getAmountFilter().compareTo(BigDecimal.ZERO) == 1)) {
                headerRow = sheet.createRow(headerRow.getRowNum() + 1);
                columnNo = 0;
                cell = headerRow.createCell(columnNo++);
                cell.setCellValue("Amount Range: " + getDataConvert()
                        .numericConvert(getAccountsWithSubsidiaryData().getAmountFilter().doubleValue()));
                cell.setCellStyle(boldStyle);
            }

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

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

            cell = headerRow.createCell(columnNo++);
            cell.setCellValue("Name");
            cell.setCellStyle(boldStyle);

            cell = headerRow.createCell(columnNo++);
            cell.setCellValue("Account Status");
            cell.setCellStyle(boldStyle);

            cell = headerRow.createCell(columnNo++);
            cell.setCellValue("Balance");
            cell.setCellStyle(boldStyle);

            for (int ii = 0; ii < getClassOpSummary().get(i).size(); ii++) {
                columnNo = 0;

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

                dataRow.createCell(columnNo++).setCellValue(getClassOpSummary().get(i).get(ii)[2].toString());
                dataRow.createCell(columnNo++).setCellValue(getClassOpSummary().get(i).get(ii)[4].toString());
                dataRow.createCell(columnNo++).setCellValue(getDataConvert()
                        .acctStatusConvert(getClassOpSummary().get(i).get(ii)[6].toString().charAt(0)));

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

                totalRow = sheet.createRow((short) dataRow.getRowNum() + 2);
            }
            if (getClassOpSummary().get(i).size() > 0) {
                cell = totalRow.createCell(1);
                cell.setCellValue("TOTAL");
                cell.setCellStyle(boldStyle);

                cell = totalRow.createCell(2);
                cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC);
                cell.setCellValue(getAccountsWithSubsidiaryData().getSubtotal().get(i).doubleValue());
                cell.setCellStyle(cellStyle);
            }
        }

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

        getExportData().fileUploadByDL(getExportData().getFilename(), "Other Current Liabilities Report",
                themeDisplay, null);

        File file = new File(getExportData().getFilename());
        if (file.exists()) {
            file.delete();
        }
    } catch (Exception e) {
        System.out.print("classOpData().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.ClassOtData.java

public void export0() {
    Integer columnNo;// w w  w  . j a v a2  s .c  o  m
    HSSFWorkbook workbook;
    HSSFSheet sheet;
    HSSFRow headerRow, dataRow, totalRow = null;
    HSSFCell cell;
    HSSFCellStyle cellStyle, boldStyle;
    HSSFFont font;

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

    getExportData().createFolder(null, themeDisplay, "Other Current Receivables 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);

        for (int i = 0; i < getAccountsWithSubsidiaryData().getAccountCodesFiltered().size(); i++) {
            try {
                sheet = workbook.createSheet(getDataConvert()
                        .accountCodeConvert(getAccountsWithSubsidiaryData().getAccountCodesFiltered().get(i)));
            } catch (Exception e) {
                sheet = workbook.createSheet(getAccountsWithSubsidiaryData().getAccountCodesFiltered().get(i));
            }

            headerRow = sheet.createRow((short) 0);
            columnNo = 0;
            cell = headerRow.createCell(columnNo++);
            cell.setCellValue(getDataConvert()
                    .accountCodeConvert(getAccountsWithSubsidiaryData().getAccountCodesFiltered().get(i)));
            cell.setCellStyle(boldStyle);

            try {
                headerRow = sheet.createRow(headerRow.getRowNum() + 1);
                columnNo = 0;
                cell = headerRow.createCell(columnNo++);
                cell.setCellValue("As of " + getCustomDate()
                        .formatDate(getAccountsWithSubsidiaryData().getReportDate(), "MM-dd-YYYY"));
                cell.setCellStyle(boldStyle);
            } catch (Exception e) {
                getAccountsWithSubsidiaryData().setReportDate(getCustomDate().getCurrentDate());

                cell.setCellValue("As of " + getCustomDate()
                        .formatDate(getAccountsWithSubsidiaryData().getReportDate(), "MM-dd-YYYY"));
                cell.setCellStyle(boldStyle);
            }

            if (getAccountsWithSubsidiaryData().getAcctCreateDateFrom() != null
                    || getAccountsWithSubsidiaryData().getAcctCreateDateTo() != null) {
                headerRow = sheet.createRow(headerRow.getRowNum() + 1);
                columnNo = 0;
                cell = headerRow.createCell(columnNo++);
                cell.setCellValue(getAccountsWithSubsidiaryData().getAcctCreateDateTo() != null
                        ? "Account Created Date: " + getCustomDate()
                                .formatDate(
                                        getAccountsWithSubsidiaryData().getAcctCreateDateFrom(), "MM-dd-YYYY")
                                .concat(" - ")
                                .concat(getCustomDate().formatDate(
                                        getAccountsWithSubsidiaryData().getAcctCreateDateTo(), "MM-dd-YYYY"))
                        : "Account Created Date: " + getCustomDate().formatDate(
                                getAccountsWithSubsidiaryData().getAcctCreateDateFrom(), "MM-dd-YYYY"));
                cell.setCellStyle(boldStyle);
            }

            if ((getAccountsWithSubsidiaryData().getAmountFilter() != null
                    && getAccountsWithSubsidiaryData().getAmountFilter().compareTo(BigDecimal.ZERO) == 1)) {
                headerRow = sheet.createRow(headerRow.getRowNum() + 1);
                columnNo = 0;
                cell = headerRow.createCell(columnNo++);
                cell.setCellValue("Amount Range: " + getDataConvert()
                        .numericConvert(getAccountsWithSubsidiaryData().getAmountFilter().doubleValue()));
                cell.setCellStyle(boldStyle);
            }

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

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

            cell = headerRow.createCell(columnNo++);
            cell.setCellValue("Name");
            cell.setCellStyle(boldStyle);

            cell = headerRow.createCell(columnNo++);
            cell.setCellValue("Account Status");
            cell.setCellStyle(boldStyle);

            cell = headerRow.createCell(columnNo++);
            cell.setCellValue("Balance");
            cell.setCellStyle(boldStyle);

            for (int ii = 0; ii < getClassOtSummary().get(i).size(); ii++) {
                columnNo = 0;

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

                dataRow.createCell(columnNo++).setCellValue(getClassOtSummary().get(i).get(ii)[2].toString());
                dataRow.createCell(columnNo++).setCellValue(getClassOtSummary().get(i).get(ii)[4].toString());
                dataRow.createCell(columnNo++).setCellValue(getDataConvert()
                        .acctStatusConvert(getClassOtSummary().get(i).get(ii)[6].toString().charAt(0)));

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

                totalRow = sheet.createRow((short) dataRow.getRowNum() + 2);
            }
            if (getClassOtSummary().get(i).size() > 0) {
                cell = totalRow.createCell(1);
                cell.setCellValue("TOTAL");
                cell.setCellStyle(boldStyle);

                cell = totalRow.createCell(2);
                cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC);
                cell.setCellValue(getAccountsWithSubsidiaryData().getSubtotal().get(i).doubleValue());
                cell.setCellStyle(cellStyle);
            }
        }

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

        getExportData().fileUploadByDL(getExportData().getFilename(), "Other Current Receivables Report",
                themeDisplay, null);

        File file = new File(getExportData().getFilename());
        if (file.exists()) {
            file.delete();
        }
    } catch (Exception e) {
        System.out.print("classOtData().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.ClassRiData.java

public void export0() {
    Integer columnNo;/*from  w  w  w  .  j  a v  a  2  s . c  o  m*/
    HSSFWorkbook workbook;
    HSSFSheet sheet;
    HSSFRow headerRow, dataRow, totalRow = null;
    HSSFCell cell;
    HSSFCellStyle cellStyle, boldStyle;
    HSSFFont font;

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

    getExportData().createFolder(null, themeDisplay, "Rental Income SL 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);

        for (int i = 0; i < getAccountsWithSubsidiaryData().getAccountCodesFiltered().size(); i++) {
            try {
                sheet = workbook.createSheet(getDataConvert()
                        .accountCodeConvert(getAccountsWithSubsidiaryData().getAccountCodesFiltered().get(i)));
            } catch (Exception e) {
                sheet = workbook.createSheet(getAccountsWithSubsidiaryData().getAccountCodesFiltered().get(i));
            }

            headerRow = sheet.createRow((short) 0);
            columnNo = 0;
            cell = headerRow.createCell(columnNo++);
            cell.setCellValue(getDataConvert()
                    .accountCodeConvert(getAccountsWithSubsidiaryData().getAccountCodesFiltered().get(i)));
            cell.setCellStyle(boldStyle);

            try {
                headerRow = sheet.createRow(headerRow.getRowNum() + 1);
                columnNo = 0;
                cell = headerRow.createCell(columnNo++);
                cell.setCellValue("As of " + getCustomDate()
                        .formatDate(getAccountsWithSubsidiaryData().getReportDate(), "MM-dd-YYYY"));
                cell.setCellStyle(boldStyle);
            } catch (Exception e) {
                getAccountsWithSubsidiaryData().setReportDate(getCustomDate().getCurrentDate());

                cell.setCellValue("As of " + getCustomDate()
                        .formatDate(getAccountsWithSubsidiaryData().getReportDate(), "MM-dd-YYYY"));
                cell.setCellStyle(boldStyle);
            }

            if (getAccountsWithSubsidiaryData().getAcctCreateDateFrom() != null
                    || getAccountsWithSubsidiaryData().getAcctCreateDateTo() != null) {
                headerRow = sheet.createRow(headerRow.getRowNum() + 1);
                columnNo = 0;
                cell = headerRow.createCell(columnNo++);
                cell.setCellValue(getAccountsWithSubsidiaryData().getAcctCreateDateTo() != null
                        ? "Account Created Date: " + getCustomDate()
                                .formatDate(
                                        getAccountsWithSubsidiaryData().getAcctCreateDateFrom(), "MM-dd-YYYY")
                                .concat(" - ")
                                .concat(getCustomDate().formatDate(
                                        getAccountsWithSubsidiaryData().getAcctCreateDateTo(), "MM-dd-YYYY"))
                        : "Account Created Date: " + getCustomDate().formatDate(
                                getAccountsWithSubsidiaryData().getAcctCreateDateFrom(), "MM-dd-YYYY"));
                cell.setCellStyle(boldStyle);
            }

            if ((getAccountsWithSubsidiaryData().getAmountFilter() != null
                    && getAccountsWithSubsidiaryData().getAmountFilter().compareTo(BigDecimal.ZERO) == 1)) {
                headerRow = sheet.createRow(headerRow.getRowNum() + 1);
                columnNo = 0;
                cell = headerRow.createCell(columnNo++);
                cell.setCellValue("Amount Range: " + getDataConvert()
                        .numericConvert(getAccountsWithSubsidiaryData().getAmountFilter().doubleValue()));
                cell.setCellStyle(boldStyle);
            }

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

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

            cell = headerRow.createCell(columnNo++);
            cell.setCellValue("Name");
            cell.setCellStyle(boldStyle);

            cell = headerRow.createCell(columnNo++);
            cell.setCellValue("Account Status");
            cell.setCellStyle(boldStyle);

            cell = headerRow.createCell(columnNo++);
            cell.setCellValue("Balance");
            cell.setCellStyle(boldStyle);

            for (int ii = 0; ii < getClassRiSummary().get(i).size(); ii++) {
                columnNo = 0;

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

                dataRow.createCell(columnNo++).setCellValue(getClassRiSummary().get(i).get(ii)[2].toString());
                dataRow.createCell(columnNo++).setCellValue(getClassRiSummary().get(i).get(ii)[4].toString());
                dataRow.createCell(columnNo++).setCellValue(getDataConvert()
                        .acctStatusConvert(getClassRiSummary().get(i).get(ii)[6].toString().charAt(0)));

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

                totalRow = sheet.createRow((short) dataRow.getRowNum() + 2);
            }
            if (getClassRiSummary().get(i).size() > 0) {
                cell = totalRow.createCell(1);
                cell.setCellValue("TOTAL");
                cell.setCellStyle(boldStyle);

                cell = totalRow.createCell(2);
                cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC);
                cell.setCellValue(getAccountsWithSubsidiaryData().getSubtotal().get(i).doubleValue());
                cell.setCellStyle(cellStyle);
            }
        }

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

        getExportData().fileUploadByDL(getExportData().getFilename(), "Rental Income SL Report", themeDisplay,
                null);

        File file = new File(getExportData().getFilename());
        if (file.exists()) {
            file.delete();
        }
    } catch (Exception e) {
        System.out.print("classRiData().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.ClassScData.java

public void export0() {
    Integer columnNo;//from   w  w w.j  a v a2s  . co  m
    HSSFWorkbook workbook;
    HSSFSheet sheet;
    HSSFRow headerRow, dataRow, totalRow = null;
    HSSFCell cell;
    HSSFCellStyle cellStyle, boldStyle;
    HSSFFont font;

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

    getExportData().createFolder(null, themeDisplay, "Share Capital 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);

        for (int i = 0; i < getAccountsWithSubsidiaryData().getAccountCodesFiltered().size(); i++) {
            try {
                sheet = workbook.createSheet(getDataConvert()
                        .accountCodeConvert(getAccountsWithSubsidiaryData().getAccountCodesFiltered().get(i)));
            } catch (Exception e) {
                sheet = workbook.createSheet(getAccountsWithSubsidiaryData().getAccountCodesFiltered().get(i));
            }

            headerRow = sheet.createRow((short) 0);
            columnNo = 0;
            cell = headerRow.createCell(columnNo++);
            cell.setCellValue(getDataConvert()
                    .accountCodeConvert(getAccountsWithSubsidiaryData().getAccountCodesFiltered().get(i)));
            cell.setCellStyle(boldStyle);

            try {
                headerRow = sheet.createRow(headerRow.getRowNum() + 1);
                columnNo = 0;
                cell = headerRow.createCell(columnNo++);
                cell.setCellValue("As of " + getCustomDate()
                        .formatDate(getAccountsWithSubsidiaryData().getReportDate(), "MM-dd-YYYY"));
                cell.setCellStyle(boldStyle);
            } catch (Exception e) {
                getAccountsWithSubsidiaryData().setReportDate(getCustomDate().getCurrentDate());

                cell.setCellValue("As of " + getCustomDate()
                        .formatDate(getAccountsWithSubsidiaryData().getReportDate(), "MM-dd-YYYY"));
                cell.setCellStyle(boldStyle);
            }

            if (getAccountsWithSubsidiaryData().getAcctCreateDateFrom() != null
                    || getAccountsWithSubsidiaryData().getAcctCreateDateTo() != null) {
                headerRow = sheet.createRow(headerRow.getRowNum() + 1);
                columnNo = 0;
                cell = headerRow.createCell(columnNo++);
                cell.setCellValue(getAccountsWithSubsidiaryData().getAcctCreateDateTo() != null
                        ? "Account Created Date: " + getCustomDate()
                                .formatDate(
                                        getAccountsWithSubsidiaryData().getAcctCreateDateFrom(), "MM-dd-YYYY")
                                .concat(" - ")
                                .concat(getCustomDate().formatDate(
                                        getAccountsWithSubsidiaryData().getAcctCreateDateTo(), "MM-dd-YYYY"))
                        : "Account Created Date: " + getCustomDate().formatDate(
                                getAccountsWithSubsidiaryData().getAcctCreateDateFrom(), "MM-dd-YYYY"));
                cell.setCellStyle(boldStyle);
            }

            if ((getAccountsWithSubsidiaryData().getAmountFilter() != null
                    && getAccountsWithSubsidiaryData().getAmountFilter().compareTo(BigDecimal.ZERO) == 1)) {
                headerRow = sheet.createRow(headerRow.getRowNum() + 1);
                columnNo = 0;
                cell = headerRow.createCell(columnNo++);
                cell.setCellValue("Amount Range: " + getDataConvert()
                        .numericConvert(getAccountsWithSubsidiaryData().getAmountFilter().doubleValue()));
                cell.setCellStyle(boldStyle);
            }

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

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

            cell = headerRow.createCell(columnNo++);
            cell.setCellValue("Name");
            cell.setCellStyle(boldStyle);

            cell = headerRow.createCell(columnNo++);
            cell.setCellValue("Account Status");
            cell.setCellStyle(boldStyle);

            cell = headerRow.createCell(columnNo++);
            cell.setCellValue("Balance");
            cell.setCellStyle(boldStyle);

            for (int ii = 0; ii < getClassScSummary().get(i).size(); ii++) {
                columnNo = 0;

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

                dataRow.createCell(columnNo++).setCellValue(getClassScSummary().get(i).get(ii)[2].toString());
                dataRow.createCell(columnNo++).setCellValue(getClassScSummary().get(i).get(ii)[4].toString());
                dataRow.createCell(columnNo++).setCellValue(getDataConvert()
                        .acctStatusConvert(getClassScSummary().get(i).get(ii)[6].toString().charAt(0)));

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

                totalRow = sheet.createRow((short) dataRow.getRowNum() + 2);
            }
            if (getClassScSummary().get(i).size() > 0) {
                cell = totalRow.createCell(1);
                cell.setCellValue("TOTAL");
                cell.setCellStyle(boldStyle);

                cell = totalRow.createCell(2);
                cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC);
                cell.setCellValue(getAccountsWithSubsidiaryData().getSubtotal().get(i).doubleValue());
                cell.setCellStyle(cellStyle);
            }
        }

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

        getExportData().fileUploadByDL(getExportData().getFilename(), "Share Capital Report", themeDisplay,
                null);

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