List of usage examples for org.apache.poi.hssf.usermodel HSSFWorkbook createCellStyle
@Override
public HSSFCellStyle createCellStyle()
From source file:bean.ClassCaData.java
public void export0() { Integer columnNo;//from w w w. ja va2 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, "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 w w.j a va 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, "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 . ja va2s .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 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;//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 . ja 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, "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.j ava2s . 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, "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 .ja va 2 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, "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); } }
From source file:bean.DamayanListingEnrolleeController.java
public void export0() throws FileNotFoundException, IOException { Integer columnNo;//from w ww. j a va 2s. com HSSFWorkbook workbook; HSSFSheet sheet; HSSFRow dataRow; HSSFCell cell; HSSFCellStyle cellStyle, boldStyle; HSSFFont font; ThemeDisplay themeDisplay = LiferayFacesContext.getInstance().getThemeDisplay(); //create folder getExportData().createFolder(null, themeDisplay, "Damayan Listing Enrollee", "DESCRIPTION"); //set filename if (getExportData().getFilename() == null || getExportData().getFilename().length() == 0) { getExportData().setFilename("Default (" + new Date() + ") "); } getExportData().setFilename(getExportData().getFilename().replace(":", "")); try { getExportData().setFilename(getExportData().getFilename().concat(".xls")); workbook = new HSSFWorkbook(); cellStyle = workbook.createCellStyle(); cellStyle.setDataFormat(HSSFDataFormat.getBuiltinFormat("#,##0.00")); font = workbook.createFont(); font.setBoldweight(Font.BOLDWEIGHT_BOLD); boldStyle = workbook.createCellStyle(); boldStyle.setFont(font); sheet = workbook.createSheet("Damayan Listing Enrollee " + getDamayanListingEnrolleeData().getCustomDate() .formatDate(getDamayanListingEnrolleeData().getDateFrom(), "MMMM dd yyyy") + " to " + getDamayanListingEnrolleeData().getCustomDate() .formatDate(getDamayanListingEnrolleeData().getDateTo(), "MMMM dd yyyy")); dataRow = sheet.createRow((short) 0); columnNo = 0; cell = dataRow.createCell(columnNo++); cell.setCellValue("DAMAYAN LISTING ENROLLEE"); cell.setCellStyle(boldStyle); dataRow = sheet.createRow(dataRow.getRowNum() + 1); columnNo = 0; cell = dataRow.createCell(columnNo++); cell.setCellValue(getDamayanListingEnrolleeData().getCustomDate() .formatDate(getDamayanListingEnrolleeData().getDateFrom(), "MMMM dd yyyy") + " to " + getDamayanListingEnrolleeData().getCustomDate() .formatDate(getDamayanListingEnrolleeData().getDateTo(), "MMMM dd yyyy")); cell.setCellStyle(boldStyle); dataRow = sheet.createRow(dataRow.getRowNum() + 1); dataRow = sheet.createRow(dataRow.getRowNum() + 1); columnNo = 0; cell = dataRow.createCell(columnNo++); cell.setCellValue("DM Account No."); cell.setCellStyle(boldStyle); columnNo = 1; cell = dataRow.createCell(columnNo++); cell.setCellValue("SC Account No."); cell.setCellStyle(boldStyle); columnNo = 2; cell = dataRow.createCell(columnNo++); cell.setCellValue("Account Name"); cell.setCellStyle(boldStyle); columnNo = 3; cell = dataRow.createCell(columnNo++); cell.setCellValue("Birthdate"); cell.setCellStyle(boldStyle); columnNo = 4; cell = dataRow.createCell(columnNo++); cell.setCellValue("Damayan Enrolled Date"); cell.setCellStyle(boldStyle); columnNo = 5; cell = dataRow.createCell(columnNo++); cell.setCellValue("Payment Type"); cell.setCellStyle(boldStyle); // dataRow.createCell(columnNo++).setCellValue(""); columnNo = 6; cell = dataRow.createCell(columnNo++); cell.setCellValue("Account Status"); cell.setCellStyle(boldStyle); columnNo = 7; cell = dataRow.createCell(columnNo++); cell.setCellValue("PD Form"); cell.setCellStyle(boldStyle); for (int i = 0; i < getDamayanListingEnrolleeData().getDamayanList().size(); i++) { dataRow = sheet.createRow(dataRow.getRowNum() + 1); //DM Account columnNo = 0; cell = dataRow.createCell(columnNo++); cell.setCellValue((String) getDamayanListingEnrolleeData().getDamayanList().get(i)[0]); cell.setCellStyle(cellStyle); //SC Account columnNo = 1; cell = dataRow.createCell(columnNo++); cell.setCellValue((String) getDamayanListingEnrolleeData().getDataConvert().convertSdToScAcctno( getDamayanListingEnrolleeData().getDamayanList().get(i)[1].toString())); cell.setCellStyle(cellStyle); //Account Name columnNo = 2; cell = dataRow.createCell(columnNo++); cell.setCellValue((String) getDamayanListingEnrolleeData().getDamayanList().get(i)[2]); cell.setCellStyle(cellStyle); //Birthdate columnNo = 3; cell = dataRow.createCell(columnNo++); cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC); cell.setCellValue(getDamayanListingEnrolleeData().getCustomDate().formatDate( (Date) getDamayanListingEnrolleeData().getDamayanList().get(i)[3], "yyyy-MM-dd")); cell.setCellStyle(cellStyle); //Damayan Enrolled Date columnNo = 4; cell = dataRow.createCell(columnNo++); cell.setCellValue((String) getDamayanListingEnrolleeData().getCustomDate().formatDate( (Date) getDamayanListingEnrolleeData().getDamayanList().get(i)[4], "yyyy-MM-dd")); cell.setCellStyle(cellStyle); //Payment Type columnNo = 5; cell = dataRow.createCell(columnNo++); cell.setCellValue((String) getDamayanListingEnrolleeData().getDamayanList().get(i)[5].toString() .replace("true", "Auto Deduction").replace("false", "Manual Deduction")); cell.setCellStyle(cellStyle); //Account Status columnNo = 6; cell = dataRow.createCell(columnNo++); cell.setCellValue((String) getDamayanListingEnrolleeData().getDataConvert().acctStatusConvert( getDamayanListingEnrolleeData().getDamayanList().get(i)[6].toString().charAt(0))); cell.setCellStyle(cellStyle); //PD Form try { columnNo = 7; cell = dataRow.createCell(columnNo++); cell.setCellValue( (String) getDamayanListingEnrolleeData().getDamayanList().get(i)[7].toString()); cell.setCellStyle(cellStyle); } catch (Exception e) { System.out.println("PD Form null " + e); } } FileOutputStream fileOutputStream = new FileOutputStream(getExportData().getFilename()); workbook.write(fileOutputStream); fileOutputStream.close(); getExportData().fileUploadByDL(getExportData().getFilename(), "Damayan Listing Enrollee", themeDisplay, null); File file = new File(getExportData().getFilename()); if (file.exists()) { file.delete(); } } catch (Exception e) { System.out.println("damayanlistingenrolleecontroller.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.DamayanListingNoticeController.java
public void export0() { Integer columnNo;//from w w w .j av a 2s . c om HSSFWorkbook workbook; HSSFSheet sheet; HSSFRow dataRow; HSSFCell cell; HSSFCellStyle cellStyle, boldStyle; HSSFFont font; ThemeDisplay themeDisplay = LiferayFacesContext.getInstance().getThemeDisplay(); //create folder getExportData().createFolder(null, themeDisplay, "Damayan Listing Notice", "DESCRIPTION"); //set filename if (getExportData().getFilename() == null || getExportData().getFilename().length() == 0) { getExportData().setFilename("Default(" + new Date() + ") "); } getExportData().setFilename(getExportData().getFilename().replace(":", "")); try { getExportData().setFilename(getExportData().getFilename().concat(".xls")); workbook = new HSSFWorkbook(); cellStyle = workbook.createCellStyle(); cellStyle.setDataFormat(HSSFDataFormat.getBuiltinFormat("#,##0.00")); font = workbook.createFont(); font.setBoldweight(Font.BOLDWEIGHT_BOLD); boldStyle = workbook.createCellStyle(); boldStyle.setFont(font); sheet = workbook.createSheet("Damayan Listing Notice " + getDamayanListingNoticeData().getCustomDate() .formatDate(getDamayanListingNoticeData().getAcctCreateDateFrom(), "MMMM dd yyyy") + " to " + getDamayanListingNoticeData().getCustomDate() .formatDate(getDamayanListingNoticeData().getAcctCreateDateTo(), "MMMM dd yyyy") + " (Amount Due - " + getDamayanListingNoticeData().getSelectedDue() + ")"); dataRow = sheet.createRow((short) 0); columnNo = 0; cell = dataRow.createCell(columnNo++); cell.setCellValue("DAMAYAN LISTING NOTICE"); cell.setCellStyle(boldStyle); dataRow = sheet.createRow(dataRow.getRowNum() + 1); columnNo = 0; cell = dataRow.createCell(columnNo++); cell.setCellValue(getDamayanListingNoticeData().getCustomDate() .formatDate(getDamayanListingNoticeData().getAcctCreateDateFrom(), "MMMM dd yyyy") + " to " + getDamayanListingNoticeData().getCustomDate() .formatDate(getDamayanListingNoticeData().getAcctCreateDateTo(), "MMMM dd yyyy") + " (Amount Due - " + getDamayanListingNoticeData().getSelectedDue() + ")"); cell.setCellStyle(boldStyle); dataRow = sheet.createRow(dataRow.getRowNum() + 1); dataRow = sheet.createRow(dataRow.getRowNum() + 1); columnNo = 0; cell = dataRow.createCell(columnNo++); cell.setCellValue("DM Account No."); cell.setCellStyle(boldStyle); columnNo = 1; cell = dataRow.createCell(columnNo++); cell.setCellValue("SC Account No."); cell.setCellStyle(boldStyle); columnNo = 2; cell = dataRow.createCell(columnNo++); cell.setCellValue("Account Name"); cell.setCellStyle(boldStyle); columnNo = 3; cell = dataRow.createCell(columnNo++); cell.setCellValue("Account Status"); cell.setCellStyle(boldStyle); columnNo = 4; cell = dataRow.createCell(columnNo++); cell.setCellValue("Payment Type"); cell.setCellStyle(boldStyle); columnNo = 5; cell = dataRow.createCell(columnNo++); cell.setCellValue("PD Form"); cell.setCellStyle(boldStyle); columnNo = 6; cell = dataRow.createCell(columnNo++); cell.setCellValue("Balance"); cell.setCellStyle(boldStyle); System.out.println("Start content"); for (int i = 0; i < getDamayanListingNoticeData().getDamayanList().size(); i++) { dataRow = sheet.createRow(dataRow.getRowNum() + 1); //DM Account No columnNo = 0; cell = dataRow.createCell(columnNo++); cell.setCellValue((String) getDamayanListingNoticeData().getDamayanList().get(i)[1]); cell.setCellStyle(cellStyle); System.out.println("DM Account No"); //SC Account No columnNo = 1; cell = dataRow.createCell(columnNo++); cell.setCellValue((String) getDamayanListingNoticeData().getDataConvert() .convertSdToScAcctno(getDamayanListingNoticeData().getDamayanList().get(i)[2].toString())); cell.setCellStyle(cellStyle); System.out.println("SC Account No"); //Account Name columnNo = 2; cell = dataRow.createCell(columnNo++); cell.setCellValue((String) getDamayanListingNoticeData().getDamayanList().get(i)[3]); cell.setCellStyle(cellStyle); System.out.println("Account Name"); //Account Status columnNo = 3; cell = dataRow.createCell(columnNo++); cell.setCellValue(getDamayanListingNoticeData().getDataConvert().acctStatusConvert( getDamayanListingNoticeData().getDamayanList().get(i)[4].toString().charAt(0))); cell.setCellStyle(cellStyle); System.out.println("Account Status"); //Payment Type columnNo = 4; cell = dataRow.createCell(columnNo++); cell.setCellValue((String) getDamayanListingNoticeData().getDamayanList().get(i)[5].toString() .replace("true", "Auto Deduction").replace("false", "Manual Deduction")); cell.setCellStyle(cellStyle); System.out.println("Payment Type"); //PD Form try { columnNo = 5; cell = dataRow.createCell(columnNo++); cell.setCellValue((String) getDamayanListingNoticeData().getDamayanList().get(i)[6].toString()); cell.setCellStyle(cellStyle); System.out.println("PD Form"); } catch (Exception e) { System.out.println("PD Form null " + e); } //Balance columnNo = 6; cell = dataRow.createCell(columnNo++); cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC); cell.setCellValue(getDamayanListingNoticeData().getDataConvert() .convertAmount((BigDecimal) getDamayanListingNoticeData().getDamayanList().get(i)[7])); cell.setCellStyle(cellStyle); System.out.println("Balance"); if (i == getDamayanListingNoticeData().getDamayanList().size() - 1) { dataRow = sheet.createRow(dataRow.getRowNum() + 1); dataRow = sheet.createRow(dataRow.getRowNum() + 1); columnNo = 4; cell = dataRow.createCell(columnNo++); cell.setCellValue("TOTAL"); cell.setCellStyle(boldStyle); dataRow.createCell(columnNo++).setCellValue(""); columnNo = 6; cell = dataRow.createCell(columnNo++); cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC); cell.setCellValue(getDamayanListingNoticeData().getDataConvert() .convertAmount(getDamayanListingNoticeData().getGrandTotal())); cell.setCellStyle(boldStyle); } System.out.println("Total"); } FileOutputStream fileOutputStream = new FileOutputStream(getExportData().getFilename()); workbook.write(fileOutputStream); fileOutputStream.close(); getExportData().fileUploadByDL(getExportData().getFilename(), "Damayan Listing Notice", themeDisplay, null); File file = new File(getExportData().getFilename()); if (file.exists()) { file.delete(); } } catch (Exception e) { System.out.println("damayanlistingnoticecontroller.export0 " + e); FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR, "Error", "An error occurred while generating excel file."); FacesContext.getCurrentInstance().addMessage(null, message); } }