Example usage for org.apache.poi.hssf.usermodel HSSFWorkbook write

List of usage examples for org.apache.poi.hssf.usermodel HSSFWorkbook write

Introduction

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

Prototype

private void write(POIFSFileSystem fs) throws IOException 

Source Link

Document

Writes the workbook out to a brand new, empty POIFS

Usage

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();//from www. j av a2  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;/*  ww  w.j  a v a  2 s  .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, "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;/*from w w w . j  av 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, "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.  ja  v  a  2s  . 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, "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;//from w w w.java 2s  .  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;//from  www  .  ja v a  2s .  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, "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  ava  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 av a 2s .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, "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);
    }
}

From source file:bean.ClassSdData.java

public void export0() throws IOException {
    Integer columnNo;//ww w. ja  va 2s.  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, "Savings Deposit 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 < getClassSdSummary().get(i).size(); ii++) {
                columnNo = 0;

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

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

                cell = dataRow.createCell(columnNo++);
                cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC);

                cell.setCellValue(((BigDecimal) getClassSdSummary().get(i).get(ii)[5]).doubleValue());
                cell.setCellStyle(cellStyle);

                totalRow = sheet.createRow((short) dataRow.getRowNum() + 2);
            }
            if (getClassSdSummary().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(), "Savings Deposit Report", themeDisplay,
                null);

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

public void export0() {
    Integer columnNo;//from  ww w. j a  va 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, "Time Deposit 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);
            //                new below
            cell = headerRow.createCell(columnNo++);
            cell.setCellValue("Certificate No.");
            cell.setCellStyle(boldStyle);
            //                new above

            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 < getClassTdSummary().get(i).size(); ii++) {
                columnNo = 0;

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

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

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

                totalRow = sheet.createRow((short) dataRow.getRowNum() + 2);
            }
            if (getClassTdSummary().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(), "Time Deposit Report", themeDisplay,
                null);

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