List of usage examples for org.apache.poi.hssf.usermodel HSSFDataFormat getBuiltinFormat
public static String getBuiltinFormat(short index)
From source file:bean.ClassTdData.java
public void export0() { Integer columnNo;//from www . ja 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, "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;// w w w. j a v a 2 s . c o m 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 ww w. ja 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 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); } }
From source file:bean.GlReportExport.java
public void export() { Integer columnNo;/*from ww w. jav a2s .co m*/ HSSFWorkbook workbook; HSSFSheet sheet; HSSFRow dataRow; HSSFCell cell; HSSFCellStyle cellStyle, boldStyle; HSSFFont font; ThemeDisplay themeDisplay = LiferayFacesContext.getInstance().getThemeDisplay(); getExportData().createFolder(null, themeDisplay, "GL Report", "DESCRIPTION"); if (getExportData().getFilename() == null || getExportData().getFilename().length() == 0) { getExportData().setFilename("Default(" + new Date() + ")"); } getExportData().setFilename(getExportData().getFilename().replace(":", "")); try { getExportData().setFilename(getExportData().getFilename().concat(".xls")); workbook = new HSSFWorkbook(); cellStyle = workbook.createCellStyle(); cellStyle.setDataFormat(HSSFDataFormat.getBuiltinFormat("#,##0.00")); font = workbook.createFont(); font.setBoldweight(Font.BOLDWEIGHT_BOLD); boldStyle = workbook.createCellStyle(); boldStyle.setFont(font); sheet = workbook.createSheet("GL Report " + exportDate()); dataRow = sheet.createRow((short) 0); columnNo = 0; cell = dataRow.createCell(columnNo++); cell.setCellValue("GL REPORT"); cell.setCellStyle(boldStyle); dataRow = sheet.createRow(dataRow.getRowNum() + 1); columnNo = 0; cell = dataRow.createCell(columnNo++); cell.setCellValue(exportDate()); cell.setCellStyle(boldStyle); dataRow = sheet.createRow(dataRow.getRowNum() + 1); dataRow = sheet.createRow(dataRow.getRowNum() + 1); columnNo = 0; cell = dataRow.createCell(columnNo++); cell.setCellValue("Date"); cell.setCellStyle(boldStyle); columnNo = 1; cell = dataRow.createCell(columnNo++); cell.setCellValue("Account Title"); cell.setCellStyle(boldStyle); columnNo = 2; cell = dataRow.createCell(columnNo++); cell.setCellValue("Journal Type"); cell.setCellStyle(boldStyle); columnNo = 3; cell = dataRow.createCell(columnNo++); cell.setCellValue("Debit"); cell.setCellStyle(boldStyle); columnNo = 4; cell = dataRow.createCell(columnNo++); cell.setCellValue("Credit"); cell.setCellStyle(boldStyle); columnNo = 5; cell = dataRow.createCell(columnNo++); cell.setCellValue("Balance"); cell.setCellStyle(boldStyle); for (int i = 0; i < getGlReportData().getGlReport().size(); i++) { dataRow = sheet.createRow(dataRow.getRowNum() + 1); //DATE columnNo = 0; cell = dataRow.createCell(columnNo++); cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC); cell.setCellValue(((Date) getGlReportData().getGlReport().get(i)[0])); cell.setCellStyle(cellStyle); cell.getDateCellValue(); // dataRow.createCell(columnNo++).setCellValue(""); //ACCOUNT TITLE columnNo = 1; cell = dataRow.createCell(columnNo++); cell.setCellValue((String) getGlReportData().getGlReport().get(i)[1]); cell.setCellStyle(cellStyle); //JOURNAL TYPE columnNo = 2; cell = dataRow.createCell(columnNo++); cell.setCellValue((String) getGlReportData().getGlReport().get(i)[2]); cell.setCellStyle(cellStyle); //DEBIT columnNo = 3; cell = dataRow.createCell(columnNo++); cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC); cell.setCellValue(((BigDecimal) getGlReportData().getGlReport().get(i)[3]).doubleValue()); cell.setCellStyle(cellStyle); //CREDIT columnNo = 4; cell = dataRow.createCell(columnNo++); cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC); cell.setCellValue(((BigDecimal) getGlReportData().getGlReport().get(i)[4]).doubleValue()); cell.setCellStyle(cellStyle); //BALANCE columnNo = 5; cell = dataRow.createCell(columnNo++); cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC); cell.setCellValue(((BigDecimal) getGlReportData().getGlReport().get(i)[5]).doubleValue()); cell.setCellStyle(cellStyle); // if (i == getSlReportData().getSlReport().size() - 1) { // dataRow = sheet.createRow(dataRow.getRowNum() + 1); // dataRow = sheet.createRow(dataRow.getRowNum() + 1); // columnNo = 0; // // cell = dataRow.createCell(columnNo++); // cell.setCellValue("TOTAL:"); // cell.setCellStyle(boldStyle); // // dataRow.createCell(columnNo++).setCellValue(""); // // columnNo = 3; // // cell = dataRow.createCell(columnNo++); // cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC); // cell.setCellValue(getDataConvert().convertAmount(getTrialBalanceData().getTrialBalanceDebitTotal())); // cell.setCellStyle(boldStyle); // // columnNo = 4; // // cell = dataRow.createCell(columnNo++); // cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC); // cell.setCellValue(getDataConvert().convertAmount(getTrialBalanceData().getTrialBalanceCreditTotal())); // cell.setCellStyle(boldStyle); // } } FileOutputStream fileOutputStream = new FileOutputStream(getExportData().getFilename()); workbook.write(fileOutputStream); fileOutputStream.close(); getExportData().fileUploadByDL(getExportData().getFilename(), "GL Report", themeDisplay, null); File file = new File(getExportData().getFilename()); if (file.exists()) { file.delete(); } } catch (Exception e) { System.out.print("glReportExport().export() " + e); FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR, "Error", "An error occurred while generating excel file."); FacesContext.getCurrentInstance().addMessage(null, message); } }
From source file:bean.SlReportExport.java
public void export() { Integer columnNo;/*from w ww. j a va 2 s .c o m*/ HSSFWorkbook workbook; HSSFSheet sheet; HSSFRow dataRow; HSSFCell cell; HSSFCellStyle cellStyle, boldStyle; HSSFFont font; ThemeDisplay themeDisplay = LiferayFacesContext.getInstance().getThemeDisplay(); getExportData().createFolder(null, themeDisplay, "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); sheet = workbook.createSheet("SL Report " + exportDate()); dataRow = sheet.createRow((short) 0); columnNo = 0; cell = dataRow.createCell(columnNo++); cell.setCellValue("SL REPORT"); cell.setCellStyle(boldStyle); dataRow = sheet.createRow(dataRow.getRowNum() + 1); columnNo = 0; cell = dataRow.createCell(columnNo++); cell.setCellValue(exportDate()); cell.setCellStyle(boldStyle); dataRow = sheet.createRow(dataRow.getRowNum() + 1); dataRow = sheet.createRow(dataRow.getRowNum() + 1); columnNo = 0; cell = dataRow.createCell(columnNo++); cell.setCellValue("Date"); cell.setCellStyle(boldStyle); columnNo = 1; cell = dataRow.createCell(columnNo++); cell.setCellValue("Account Title"); cell.setCellStyle(boldStyle); columnNo = 2; cell = dataRow.createCell(columnNo++); cell.setCellValue("Journal Type"); cell.setCellStyle(boldStyle); columnNo = 3; cell = dataRow.createCell(columnNo++); cell.setCellValue("Debit"); cell.setCellStyle(boldStyle); columnNo = 4; cell = dataRow.createCell(columnNo++); cell.setCellValue("Credit"); cell.setCellStyle(boldStyle); columnNo = 5; cell = dataRow.createCell(columnNo++); cell.setCellValue("Balance"); cell.setCellStyle(boldStyle); for (int i = 0; i < getSlReportData().getSlReport().size(); i++) { dataRow = sheet.createRow(dataRow.getRowNum() + 1); //DATE columnNo = 0; cell = dataRow.createCell(columnNo++); // cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC); cell.setCellValue((Date) getSlReportData().getSlReport().get(i)[0]); cell.setCellStyle(cellStyle); // dataRow.createCell(columnNo++).setCellValue(""); //ACCOUNT TITLE columnNo = 1; cell = dataRow.createCell(columnNo++); cell.setCellValue((String) getSlReportData().getSlReport().get(i)[1]); cell.setCellStyle(cellStyle); //JOURNAL TYPE columnNo = 2; cell = dataRow.createCell(columnNo++); cell.setCellValue((String) getSlReportData().getSlReport().get(i)[2]); cell.setCellStyle(cellStyle); //DEBIT columnNo = 3; cell = dataRow.createCell(columnNo++); cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC); cell.setCellValue(((BigDecimal) getSlReportData().getSlReport().get(i)[3]).doubleValue()); cell.setCellStyle(cellStyle); //CREDIT columnNo = 4; cell = dataRow.createCell(columnNo++); cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC); cell.setCellValue(((BigDecimal) getSlReportData().getSlReport().get(i)[4]).doubleValue()); cell.setCellStyle(cellStyle); //BALANCE columnNo = 5; cell = dataRow.createCell(columnNo++); cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC); cell.setCellValue(((BigDecimal) getSlReportData().getSlReport().get(i)[5]).doubleValue()); cell.setCellStyle(cellStyle); // if (i == getSlReportData().getSlReport().size() - 1) { // dataRow = sheet.createRow(dataRow.getRowNum() + 1); // dataRow = sheet.createRow(dataRow.getRowNum() + 1); // columnNo = 0; // // cell = dataRow.createCell(columnNo++); // cell.setCellValue("TOTAL:"); // cell.setCellStyle(boldStyle); // // dataRow.createCell(columnNo++).setCellValue(""); // // columnNo = 3; // // cell = dataRow.createCell(columnNo++); // cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC); // cell.setCellValue(getDataConvert().convertAmount(getTrialBalanceData().getTrialBalanceDebitTotal())); // cell.setCellStyle(boldStyle); // // columnNo = 4; // // cell = dataRow.createCell(columnNo++); // cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC); // cell.setCellValue(getDataConvert().convertAmount(getTrialBalanceData().getTrialBalanceCreditTotal())); // cell.setCellStyle(boldStyle); // } } FileOutputStream fileOutputStream = new FileOutputStream(getExportData().getFilename()); workbook.write(fileOutputStream); fileOutputStream.close(); getExportData().fileUploadByDL(getExportData().getFilename(), "SL Report", themeDisplay, null); File file = new File(getExportData().getFilename()); if (file.exists()) { file.delete(); } } catch (Exception e) { System.out.print("slReportExport().export() " + e); FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR, "Error", "An error occurred while generating excel file."); FacesContext.getCurrentInstance().addMessage(null, message); } }
From source file:bean.StatementOfFinancialConditionExport.java
public void export0() { Integer columnNo;//from www. j ava 2s. c om HSSFWorkbook workbook; HSSFSheet sheet; HSSFRow dataRow; HSSFCell cell; HSSFCellStyle cellStyle, boldStyle; HSSFFont font; ThemeDisplay themeDisplay = LiferayFacesContext.getInstance().getThemeDisplay(); getExportData().createFolder(null, themeDisplay, "Statement of Financial Condition Report", "DESCRIPTION"); if (getExportData().getFilename() == null || getExportData().getFilename().length() == 0) { getExportData().setFilename("Default(" + new Date() + ")"); } getExportData().setFilename(getExportData().getFilename().replace(":", "")); try { getExportData().setFilename(getExportData().getFilename().concat(".xls")); workbook = new HSSFWorkbook(); cellStyle = workbook.createCellStyle(); cellStyle.setDataFormat(HSSFDataFormat.getBuiltinFormat("#,##0.00")); font = workbook.createFont(); font.setBoldweight(Font.BOLDWEIGHT_BOLD); boldStyle = workbook.createCellStyle(); boldStyle.setFont(font); sheet = workbook.createSheet( "Statement of Financial Condition Report " + getFinancialReportData().getCurrentMonth() != null ? getDataConvert().monthConvert(getFinancialReportData().getCurrentMonth()) + " " + getFinancialReportData().getCurrentYear().toString() : getFinancialReportData().getCurrentYear().toString()); dataRow = sheet.createRow((short) 0); columnNo = 0; cell = dataRow.createCell(columnNo++); cell.setCellValue("STATEMENT OF FINANCIAL CONDITION"); cell.setCellStyle(boldStyle); dataRow = sheet.createRow(dataRow.getRowNum() + 1); columnNo = 0; cell = dataRow.createCell(columnNo++); cell.setCellValue(getFinancialReportData().getCurrentMonth() != null ? getDataConvert().monthConvert(getFinancialReportData().getCurrentMonth()) + " " + getFinancialReportData().getCurrentYear().toString() : getFinancialReportData().getCurrentYear().toString()); cell.setCellStyle(boldStyle); dataRow = sheet.createRow(dataRow.getRowNum() + 1); dataRow = sheet.createRow(dataRow.getRowNum() + 1); columnNo = 0; cell = dataRow.createCell(columnNo++); cell.setCellValue("ASSETS"); cell.setCellStyle(boldStyle); // for (int i = 0; i < getStatementOfFinancialConditionData().getAssetsLevel2().size(); i++) { dataRow = sheet.createRow(dataRow.getRowNum() + 1); columnNo = 0; cell = dataRow.createCell(columnNo++); cell.setCellValue(getStatementOfFinancialConditionData().getAssetsLevel2().get(i).getAcctTitle()); cell.setCellStyle(boldStyle); // dataRow.createCell(columnNo++).setCellValue(""); if (getStatementOfFinancialConditionData().getAssetsLevel3().get(i).isEmpty()) { cell = dataRow.createCell(columnNo++); cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC); cell.setCellValue(getStatementOfFinancialConditionData().getAssetsLevel2().get(i).getAmount() .doubleValue()); cell.setCellStyle(cellStyle); } // for (int ii = 0; ii < getStatementOfFinancialConditionData().getAssetsLevel3().get(i) .size(); ii++) { dataRow = sheet.createRow(dataRow.getRowNum() + 1); columnNo = 0; dataRow.createCell(columnNo++).setCellValue(""); dataRow.createCell(columnNo++).setCellValue( getStatementOfFinancialConditionData().getAssetsLevel3().get(i).get(ii).getAcctTitle()); cell = dataRow.createCell(columnNo++); cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC); cell.setCellValue(getStatementOfFinancialConditionData().getAssetsLevel3().get(i).get(ii) .getAmount().doubleValue()); cell.setCellStyle(cellStyle); if (ii == getStatementOfFinancialConditionData().getAssetsLevel3().get(i).size() - 1) { dataRow = sheet.createRow(dataRow.getRowNum() + 1); columnNo = 0; dataRow.createCell(columnNo++).setCellValue(""); cell = dataRow.createCell(columnNo++); cell.setCellValue("TOTAL"); cell.setCellStyle(boldStyle); cell = dataRow.createCell(columnNo++); cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC); cell.setCellValue( getStatementOfFinancialConditionData().getAssetsLevel2Total().get(i).doubleValue()); cell.setCellStyle(cellStyle); } } if (i == getStatementOfFinancialConditionData().getAssetsLevel2().size() - 1) { dataRow = sheet.createRow(dataRow.getRowNum() + 1); columnNo = 0; cell = dataRow.createCell(columnNo++); cell.setCellValue("TOTAL ASSETS"); cell.setCellStyle(boldStyle); dataRow.createCell(columnNo++).setCellValue(""); cell = dataRow.createCell(columnNo++); cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC); // cell.setCellValue(getStatementOfFinancialConditionData().getAssetsLevel2Total().get(i).doubleValue()); cell.setCellValue(getStatementOfFinancialConditionData().getAssetLevel1Total().doubleValue()); cell.setCellStyle(cellStyle); } } // dataRow = sheet.createRow(dataRow.getRowNum() + 1); dataRow = sheet.createRow(dataRow.getRowNum() + 1); columnNo = 0; cell = dataRow.createCell(columnNo++); cell.setCellValue("LIABILITIES AND EQUITY"); cell.setCellStyle(boldStyle); dataRow = sheet.createRow(dataRow.getRowNum() + 1); dataRow = sheet.createRow(dataRow.getRowNum() + 1); columnNo = 0; cell = dataRow.createCell(columnNo++); cell.setCellValue("LIABILITIES"); cell.setCellStyle(boldStyle); // for (int i = 0; i < getStatementOfFinancialConditionData().getLiabilitiesLevel2().size(); i++) { dataRow = sheet.createRow(dataRow.getRowNum() + 1); columnNo = 0; cell = dataRow.createCell(columnNo++); cell.setCellValue( getStatementOfFinancialConditionData().getLiabilitiesLevel2().get(i).getAcctTitle()); cell.setCellStyle(boldStyle); // dataRow.createCell(columnNo++).setCellValue(""); if (getStatementOfFinancialConditionData().getLiabilitiesLevel3().get(i).isEmpty()) { cell = dataRow.createCell(columnNo++); cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC); cell.setCellValue(getStatementOfFinancialConditionData().getLiabilitiesLevel2().get(i) .getAmount().doubleValue()); cell.setCellStyle(cellStyle); } // for (int ii = 0; ii < getStatementOfFinancialConditionData().getLiabilitiesLevel3().get(i) .size(); ii++) { dataRow = sheet.createRow(dataRow.getRowNum() + 1); columnNo = 0; dataRow.createCell(columnNo++).setCellValue(""); dataRow.createCell(columnNo++).setCellValue(getStatementOfFinancialConditionData() .getLiabilitiesLevel3().get(i).get(ii).getAcctTitle()); cell = dataRow.createCell(columnNo++); cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC); cell.setCellValue(getStatementOfFinancialConditionData().getLiabilitiesLevel3().get(i).get(ii) .getAmount().doubleValue()); cell.setCellStyle(cellStyle); if (ii == getStatementOfFinancialConditionData().getLiabilitiesLevel3().get(i).size() - 1) { dataRow = sheet.createRow(dataRow.getRowNum() + 1); columnNo = 0; dataRow.createCell(columnNo++).setCellValue(""); cell = dataRow.createCell(columnNo++); cell.setCellValue("TOTAL"); cell.setCellStyle(boldStyle); cell = dataRow.createCell(columnNo++); cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC); cell.setCellValue(getStatementOfFinancialConditionData().getLiabilitiesLevel2Total().get(i) .doubleValue()); cell.setCellStyle(cellStyle); } } if (i == getStatementOfFinancialConditionData().getLiabilitiesLevel2().size() - 1) { dataRow = sheet.createRow(dataRow.getRowNum() + 1); columnNo = 0; cell = dataRow.createCell(columnNo++); cell.setCellValue("TOTAL LIABILITIES"); cell.setCellStyle(boldStyle); dataRow.createCell(columnNo++).setCellValue(""); cell = dataRow.createCell(columnNo++); cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC); // cell.setCellValue(getStatementOfFinancialConditionData().getLiabilitiesLevel2Total().get(i).doubleValue()); cell.setCellValue( getStatementOfFinancialConditionData().getLiabilityLevel1Total().doubleValue()); cell.setCellStyle(cellStyle); } } // dataRow = sheet.createRow(dataRow.getRowNum() + 1); dataRow = sheet.createRow(dataRow.getRowNum() + 1); columnNo = 0; cell = dataRow.createCell(columnNo++); cell.setCellValue("EQUITY"); cell.setCellStyle(boldStyle); // for (int i = 0; i < getStatementOfFinancialConditionData().getEquitiesLevel2().size(); i++) { dataRow = sheet.createRow(dataRow.getRowNum() + 1); columnNo = 0; cell = dataRow.createCell(columnNo++); cell.setCellValue(getStatementOfFinancialConditionData().getEquitiesLevel2().get(i).getAcctTitle()); cell.setCellStyle(boldStyle); // dataRow.createCell(columnNo++).setCellValue(""); if (getStatementOfFinancialConditionData().getEquitiesLevel3().get(i).isEmpty()) { cell = dataRow.createCell(columnNo++); cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC); cell.setCellValue(getStatementOfFinancialConditionData().getEquitiesLevel2().get(i).getAmount() .doubleValue()); cell.setCellStyle(cellStyle); } // for (int ii = 0; ii < getStatementOfFinancialConditionData().getEquitiesLevel3().get(i) .size(); ii++) { dataRow = sheet.createRow(dataRow.getRowNum() + 1); columnNo = 0; dataRow.createCell(columnNo++).setCellValue(""); dataRow.createCell(columnNo++).setCellValue(getStatementOfFinancialConditionData() .getEquitiesLevel3().get(i).get(ii).getAcctTitle()); cell = dataRow.createCell(columnNo++); cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC); cell.setCellValue(getStatementOfFinancialConditionData().getEquitiesLevel3().get(i).get(ii) .getAmount().doubleValue()); cell.setCellStyle(cellStyle); if (ii == getStatementOfFinancialConditionData().getEquitiesLevel3().get(i).size() - 1) { dataRow = sheet.createRow(dataRow.getRowNum() + 1); columnNo = 0; dataRow.createCell(columnNo++).setCellValue(""); cell = dataRow.createCell(columnNo++); cell.setCellValue("TOTAL"); cell.setCellStyle(boldStyle); cell = dataRow.createCell(columnNo++); cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC); cell.setCellValue(getStatementOfFinancialConditionData().getEquitiesLevel2Total().get(i) .doubleValue()); cell.setCellStyle(cellStyle); } } if (i == getStatementOfFinancialConditionData().getEquitiesLevel2().size() - 1) { dataRow = sheet.createRow(dataRow.getRowNum() + 1); columnNo = 0; cell = dataRow.createCell(columnNo++); cell.setCellValue("TOTAL EQUITY"); cell.setCellStyle(boldStyle); dataRow.createCell(columnNo++).setCellValue(""); cell = dataRow.createCell(columnNo++); cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC); // cell.setCellValue(getStatementOfFinancialConditionData().getEquitiesLevel2Total().get(i).doubleValue()); cell.setCellValue(getStatementOfFinancialConditionData().getEquityLevel1Total().doubleValue()); cell.setCellStyle(cellStyle); dataRow = sheet.createRow(dataRow.getRowNum() + 1); columnNo = 0; cell = dataRow.createCell(columnNo++); cell.setCellValue("TOTAL LIABILITIES AND EQUITY"); cell.setCellStyle(boldStyle); dataRow.createCell(columnNo++).setCellValue(""); cell = dataRow.createCell(columnNo++); cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC); cell.setCellValue( getStatementOfFinancialConditionData().getLiabilityEquityLevel1Total().doubleValue()); cell.setCellStyle(cellStyle); } } FileOutputStream fileOutputStream = new FileOutputStream(getExportData().getFilename()); workbook.write(fileOutputStream); fileOutputStream.close(); getExportData().fileUploadByDL(getExportData().getFilename(), "Statement of Financial Condition Report", themeDisplay, null); File file = new File(getExportData().getFilename()); if (file.exists()) { file.delete(); } } catch (Exception e) { System.out.print("statementOfFinancialConditionExport().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.StatementOfOperationsExport.java
public void export0() { Integer columnNo;/*w ww. j ava 2 s . c o m*/ HSSFWorkbook workbook; HSSFSheet sheet; HSSFRow dataRow; HSSFCell cell; HSSFCellStyle cellStyle, boldStyle; HSSFFont font; ThemeDisplay themeDisplay = LiferayFacesContext.getInstance().getThemeDisplay(); getExportData().createFolder(null, themeDisplay, "Statement of Operations Report", "DESCRIPTION"); if (getExportData().getFilename() == null || getExportData().getFilename().length() == 0) { getExportData().setFilename("Default(" + new Date() + ")"); } getExportData().setFilename(getExportData().getFilename().replace(":", "")); try { getExportData().setFilename(getExportData().getFilename().concat(".xls")); workbook = new HSSFWorkbook(); cellStyle = workbook.createCellStyle(); cellStyle.setDataFormat(HSSFDataFormat.getBuiltinFormat("#,##0.00")); font = workbook.createFont(); font.setBoldweight(Font.BOLDWEIGHT_BOLD); boldStyle = workbook.createCellStyle(); boldStyle.setFont(font); sheet = workbook.createSheet( "Statement of Operations Report " + getFinancialReportData().getCurrentMonth() != null ? getDataConvert().monthConvert(getFinancialReportData().getCurrentMonth()) + " " + getFinancialReportData().getCurrentYear().toString() : getFinancialReportData().getCurrentYear().toString()); dataRow = sheet.createRow((short) 0); columnNo = 0; cell = dataRow.createCell(columnNo++); cell.setCellValue("STATEMENT OF OPERATIONS"); cell.setCellStyle(boldStyle); dataRow = sheet.createRow(dataRow.getRowNum() + 1); columnNo = 0; cell = dataRow.createCell(columnNo++); cell.setCellValue(getFinancialReportData().getCurrentMonth() != null ? getDataConvert().monthConvert(getFinancialReportData().getCurrentMonth()) + " " + getFinancialReportData().getCurrentYear().toString() : getFinancialReportData().getCurrentYear().toString()); cell.setCellStyle(boldStyle); dataRow = sheet.createRow(dataRow.getRowNum() + 1); dataRow = sheet.createRow(dataRow.getRowNum() + 1); columnNo = 0; cell = dataRow.createCell(columnNo++); cell.setCellValue("INCOME"); cell.setCellStyle(boldStyle); // for (int i = 0; i < getStatementOfOperationsData().getIncomeLevel2().size(); i++) { dataRow = sheet.createRow(dataRow.getRowNum() + 1); columnNo = 0; cell = dataRow.createCell(columnNo++); cell.setCellValue(getStatementOfOperationsData().getIncomeLevel2().get(i).getAcctTitle()); cell.setCellStyle(boldStyle); // dataRow.createCell(columnNo++).setCellValue(""); if (getStatementOfOperationsData().getIncomeLevel3().get(i).isEmpty()) { cell = dataRow.createCell(columnNo++); cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC); cell.setCellValue( getStatementOfOperationsData().getIncomeLevel2().get(i).getAmount().doubleValue()); cell.setCellStyle(cellStyle); } // for (int ii = 0; ii < getStatementOfOperationsData().getIncomeLevel3().get(i).size(); ii++) { dataRow = sheet.createRow(dataRow.getRowNum() + 1); columnNo = 0; dataRow.createCell(columnNo++).setCellValue(""); dataRow.createCell(columnNo++).setCellValue( getStatementOfOperationsData().getIncomeLevel3().get(i).get(ii).getAcctTitle()); cell = dataRow.createCell(columnNo++); cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC); cell.setCellValue(getStatementOfOperationsData().getIncomeLevel3().get(i).get(ii).getAmount() .doubleValue()); cell.setCellStyle(cellStyle); if (ii == getStatementOfOperationsData().getIncomeLevel3().get(i).size() - 1) { dataRow = sheet.createRow(dataRow.getRowNum() + 1); columnNo = 0; dataRow.createCell(columnNo++).setCellValue(""); cell = dataRow.createCell(columnNo++); cell.setCellValue("TOTAL"); cell.setCellStyle(boldStyle); cell = dataRow.createCell(columnNo++); cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC); cell.setCellValue( getStatementOfOperationsData().getIncomeLevel2Total().get(i).doubleValue()); cell.setCellStyle(cellStyle); } } if (i == getStatementOfOperationsData().getIncomeLevel2().size() - 1) { dataRow = sheet.createRow(dataRow.getRowNum() + 1); columnNo = 0; cell = dataRow.createCell(columnNo++); cell.setCellValue("TOTAL INCOME"); cell.setCellStyle(boldStyle); dataRow.createCell(columnNo++).setCellValue(""); cell = dataRow.createCell(columnNo++); cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC); // cell.setCellValue(getStatementOfOperationsData().getIncomeLevel2Total().get(i).doubleValue()); cell.setCellValue(getStatementOfOperationsData().getIncomeLevel1Total().doubleValue()); cell.setCellStyle(cellStyle); } } // dataRow = sheet.createRow(dataRow.getRowNum() + 1); dataRow = sheet.createRow(dataRow.getRowNum() + 1); columnNo = 0; cell = dataRow.createCell(columnNo++); cell.setCellValue("EXPENSES"); cell.setCellStyle(boldStyle); // for (int i = 0; i < getStatementOfOperationsData().getExpensesLevel2().size(); i++) { dataRow = sheet.createRow(dataRow.getRowNum() + 1); columnNo = 0; cell = dataRow.createCell(columnNo++); cell.setCellValue(getStatementOfOperationsData().getExpensesLevel2().get(i).getAcctTitle()); cell.setCellStyle(boldStyle); // dataRow.createCell(columnNo++).setCellValue(""); if (getStatementOfOperationsData().getExpensesLevel3().get(i).isEmpty()) { cell = dataRow.createCell(columnNo++); cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC); cell.setCellValue( getStatementOfOperationsData().getExpensesLevel2().get(i).getAmount().doubleValue()); cell.setCellStyle(cellStyle); } // for (int ii = 0; ii < getStatementOfOperationsData().getExpensesLevel3().get(i).size(); ii++) { dataRow = sheet.createRow(dataRow.getRowNum() + 1); columnNo = 0; dataRow.createCell(columnNo++).setCellValue(""); dataRow.createCell(columnNo++).setCellValue( getStatementOfOperationsData().getExpensesLevel3().get(i).get(ii).getAcctTitle()); cell = dataRow.createCell(columnNo++); cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC); cell.setCellValue(getStatementOfOperationsData().getExpensesLevel3().get(i).get(ii).getAmount() .doubleValue()); cell.setCellStyle(cellStyle); if (ii == getStatementOfOperationsData().getExpensesLevel3().get(i).size() - 1) { dataRow = sheet.createRow(dataRow.getRowNum() + 1); columnNo = 0; dataRow.createCell(columnNo++).setCellValue(""); cell = dataRow.createCell(columnNo++); cell.setCellValue("TOTAL"); cell.setCellStyle(boldStyle); cell = dataRow.createCell(columnNo++); cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC); cell.setCellValue( getStatementOfOperationsData().getExpensesLevel2Total().get(i).doubleValue()); cell.setCellStyle(cellStyle); } } if (i == getStatementOfOperationsData().getExpensesLevel2().size() - 1) { dataRow = sheet.createRow(dataRow.getRowNum() + 1); columnNo = 0; cell = dataRow.createCell(columnNo++); cell.setCellValue("TOTAL EXPENSES"); cell.setCellStyle(boldStyle); dataRow.createCell(columnNo++).setCellValue(""); cell = dataRow.createCell(columnNo++); cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC); // cell.setCellValue(getStatementOfOperationsData().getExpensesLevel2Total().get(i).doubleValue()); cell.setCellValue(getStatementOfOperationsData().getExpenseLevel1Total().doubleValue()); cell.setCellStyle(cellStyle); } } FileOutputStream fileOutputStream = new FileOutputStream(getExportData().getFilename()); workbook.write(fileOutputStream); fileOutputStream.close(); getExportData().fileUploadByDL(getExportData().getFilename(), "Statement of Operations Report", themeDisplay, null); File file = new File(getExportData().getFilename()); if (file.exists()) { file.delete(); } } catch (Exception e) { System.out.print("statementOfOperationsExport().export0() " + e); FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR, "Error", "An error occurred while generating excel file."); FacesContext.getCurrentInstance().addMessage(null, message); } }
From source file:bean.TrialBalanceExport.java
public void export() { Integer columnNo;/*from w w w .j av a2 s .co m*/ HSSFWorkbook workbook; HSSFSheet sheet; HSSFRow dataRow; HSSFCell cell; HSSFCellStyle cellStyle, boldStyle; HSSFFont font; ThemeDisplay themeDisplay = LiferayFacesContext.getInstance().getThemeDisplay(); getExportData().createFolder(null, themeDisplay, "Trial Balance Report", "DESCRIPTION"); if (getExportData().getFilename() == null || getExportData().getFilename().length() == 0) { getExportData().setFilename("Default(" + new Date() + ")"); } getExportData().setFilename(getExportData().getFilename().replace(":", "")); try { getExportData().setFilename(getExportData().getFilename().concat(".xls")); workbook = new HSSFWorkbook(); cellStyle = workbook.createCellStyle(); cellStyle.setDataFormat(HSSFDataFormat.getBuiltinFormat("#,##0.00")); font = workbook.createFont(); font.setBoldweight(Font.BOLDWEIGHT_BOLD); boldStyle = workbook.createCellStyle(); boldStyle.setFont(font); sheet = workbook .createSheet("Trial Balance Report " + getFinancialReportData().getCurrentMonth() != null ? getDataConvert().monthConvert(getFinancialReportData().getCurrentMonth()) + " " + getFinancialReportData().getCurrentYear().toString() : getFinancialReportData().getCurrentYear().toString()); dataRow = sheet.createRow((short) 0); columnNo = 0; cell = dataRow.createCell(columnNo++); cell.setCellValue("TRIAL BALANCE"); cell.setCellStyle(boldStyle); dataRow = sheet.createRow(dataRow.getRowNum() + 1); columnNo = 0; cell = dataRow.createCell(columnNo++); cell.setCellValue(getFinancialReportData().getCurrentMonth() != null ? getDataConvert().monthConvert(getFinancialReportData().getCurrentMonth()) + " " + getFinancialReportData().getCurrentYear().toString() : getFinancialReportData().getCurrentYear().toString()); cell.setCellStyle(boldStyle); dataRow = sheet.createRow(dataRow.getRowNum() + 1); dataRow = sheet.createRow(dataRow.getRowNum() + 1); columnNo = 0; cell = dataRow.createCell(columnNo++); cell.setCellValue("Account Title"); cell.setCellStyle(boldStyle); columnNo = 1; cell = dataRow.createCell(columnNo++); cell.setCellValue("Debit"); cell.setCellStyle(boldStyle); columnNo = 2; cell = dataRow.createCell(columnNo++); cell.setCellValue("Credit"); cell.setCellStyle(boldStyle); if (getTrialBalanceData().getType() == 1) { for (int i = 0; i < getTrialBalanceData().getCombotb().size(); i++) { for (int ii = 0; ii < getTrialBalanceData().getCombotb().get(i).size(); ii++) { dataRow = sheet.createRow(dataRow.getRowNum() + 1); columnNo = 0; cell = dataRow.createCell(columnNo++); cell.setCellValue(getDataConvert() .accountCodeConvert((String) getTrialBalanceData().getCombotb().get(i).get(ii)[0])); cell.setCellStyle(cellStyle); // dataRow.createCell(columnNo++).setCellValue(""); columnNo = 1; cell = dataRow.createCell(columnNo++); cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC); cell.setCellValue( ((BigDecimal) getTrialBalanceData().getCombotb().get(i).get(ii)[1]).doubleValue()); cell.setCellStyle(cellStyle); columnNo = 2; cell = dataRow.createCell(columnNo++); cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC); cell.setCellValue( ((BigDecimal) getTrialBalanceData().getCombotb().get(i).get(ii)[2]).doubleValue()); cell.setCellStyle(cellStyle); } if (i == getTrialBalanceData().getCombotb().size() - 1) { dataRow = sheet.createRow(dataRow.getRowNum() + 1); dataRow = sheet.createRow(dataRow.getRowNum() + 1); columnNo = 0; cell = dataRow.createCell(columnNo++); cell.setCellValue("TOTAL:"); cell.setCellStyle(boldStyle); dataRow.createCell(columnNo++).setCellValue(""); columnNo = 1; cell = dataRow.createCell(columnNo++); cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC); cell.setCellValue(((getTrialBalanceData().getComboDebitTotal()).doubleValue())); cell.setCellStyle(boldStyle); System.out.println("debit total " + getDataConvert().convertAmount(getTrialBalanceData().getComboDebitTotal())); columnNo = 2; cell = dataRow.createCell(columnNo++); cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC); cell.setCellValue(((getTrialBalanceData().getComboCreditTotal()).doubleValue())); cell.setCellStyle(boldStyle); System.out.println("credit total " + getDataConvert().convertAmount(getTrialBalanceData().getComboCreditTotal())); } } } else if (getTrialBalanceData().getType() == 2) { for (int i = 0; i < getTrialBalanceData().getTrialBalance().size(); i++) { dataRow = sheet.createRow(dataRow.getRowNum() + 1); columnNo = 0; cell = dataRow.createCell(columnNo++); cell.setCellValue((String) getTrialBalanceData().getTrialBalance().get(i).getAcctTitle()); cell.setCellStyle(cellStyle); // dataRow.createCell(columnNo++).setCellValue(""); columnNo = 1; cell = dataRow.createCell(columnNo++); cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC); cell.setCellValue(getDataConvert() .convertAmount((BigDecimal) getTrialBalanceData().getTrialBalance().get(i).getDebit())); cell.setCellStyle(cellStyle); columnNo = 2; cell = dataRow.createCell(columnNo++); cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC); cell.setCellValue(getDataConvert().convertAmount( (BigDecimal) getTrialBalanceData().getTrialBalance().get(i).getCredit())); cell.setCellStyle(cellStyle); if (i == getTrialBalanceData().getTrialBalance().size() - 1) { dataRow = sheet.createRow(dataRow.getRowNum() + 1); dataRow = sheet.createRow(dataRow.getRowNum() + 1); columnNo = 0; cell = dataRow.createCell(columnNo++); cell.setCellValue("TOTAL:"); cell.setCellStyle(boldStyle); dataRow.createCell(columnNo++).setCellValue(""); columnNo = 1; cell = dataRow.createCell(columnNo++); cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC); cell.setCellValue( getDataConvert().convertAmount(getTrialBalanceData().getTrialBalanceDebitTotal())); cell.setCellStyle(boldStyle); columnNo = 2; cell = dataRow.createCell(columnNo++); cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC); cell.setCellValue( getDataConvert().convertAmount(getTrialBalanceData().getTrialBalanceCreditTotal())); cell.setCellStyle(boldStyle); } } } FileOutputStream fileOutputStream = new FileOutputStream(getExportData().getFilename()); workbook.write(fileOutputStream); fileOutputStream.close(); getExportData().fileUploadByDL(getExportData().getFilename(), "Trial Balance Report", themeDisplay, null); File file = new File(getExportData().getFilename()); if (file.exists()) { file.delete(); } } catch (Exception e) { System.out.print("trialBalanceExport().export() " + e); FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR, "Error", "An error occurred while generating excel file."); FacesContext.getCurrentInstance().addMessage(null, message); } }
From source file:br.ufpa.psi.comportamente.labgame.mbeans.RelatoriosMB.java
License:Open Source License
public StreamedContent geraRelatorioJogadasExperimento() throws ParsePropertyException, IOException, InvalidFormatException { HSSFWorkbook workbook = new HSSFWorkbook(); HSSFSheet sheet = workbook.createSheet("Relatrio das Jogadas"); sheet.setColumnWidth(sheet.getFirstRowNum(), (14 * 256) + 200); sheet.setColumnWidth(1, (14 * 256) + 200); sheet.setColumnWidth(4, (17 * 256) + 200); sheet.setColumnWidth(5, (16 * 256) + 200); HSSFCellStyle cs1 = workbook.createCellStyle(); cs1.setDataFormat(HSSFDataFormat.getBuiltinFormat("d-mmm-yy")); HSSFCellStyle cs2 = workbook.createCellStyle(); cs2.setDataFormat(HSSFDataFormat.getBuiltinFormat("h:mm:ss")); JogadaDAO jogadaDAO = new JogadaDAO(); jogadaDAO.beginTransaction();/*from w ww . j a va2 s. c om*/ List<Jogada> jogadas = jogadaDAO.encontrarPorExperimento(experimentoSelecionado.getId()); int countRow = 0; Row row1 = sheet.createRow(countRow++); Cell cell = row1.createCell(0); cell.setCellValue("Experimento: " + experimentoSelecionado.getNome()); Row row = sheet.createRow(countRow++); row.createCell(0).setCellValue("Data da Jogada"); row.createCell(1).setCellValue("Hora da Jogada"); row.createCell(2).setCellValue("Coluna"); row.createCell(3).setCellValue("Linha"); row.createCell(4).setCellValue("Pontuacao Individual"); row.createCell(5).setCellValue("Pontuacao Coletiva"); row.createCell(6).setCellValue("Participante"); row.createCell(7).setCellValue("Condio"); for (Jogada jogada : jogadas) { Row nrow = sheet.createRow(countRow++); //Data Cell ncell0 = nrow.createCell(0); ncell0.setCellValue(jogada.getMomento()); ncell0.setCellStyle(cs1); //Hora Cell ncell1 = nrow.createCell(1); ncell1.setCellValue(jogada.getMomento()); ncell1.setCellStyle(cs2); //Coluna Cell ncell2 = nrow.createCell(2); ncell2.setCellValue(jogada.getColunaSelecionada()); //Linha Cell ncell3 = nrow.createCell(3); ncell3.setCellValue(jogada.getLinhaSelecionada()); //Pontuao Individual Cell ncell4 = nrow.createCell(4); ncell4.setCellValue(jogada.getPontuacaoIndividual()); //Pontuao Coletiva Cell ncell5 = nrow.createCell(5); ncell5.setCellValue(jogada.getPontuacaoCultural()); //Jogador Cell ncell6 = nrow.createCell(6); ncell6.setCellValue(jogada.getJogador().getNome()); //Id da Condio Cell ncell7 = nrow.createCell(7); ncell7.setCellValue(jogada.getIdCondicao()); } jogadaDAO.stopOperation(false); byte[] bytes; try (ByteArrayOutputStream out = new ByteArrayOutputStream()) { workbook.write(out); bytes = out.toByteArray(); } InputStream ioStream = new ByteArrayInputStream(bytes); file = new DefaultStreamedContent(ioStream, "application/vnd.ms-excel", "Relatrio_Jogadas.xls"); return file; }
From source file:bs.global.util.ExcelFactory.java
private void writeCell(HSSFRow row, int col, Object value, FormatType formatType, Short bgColor, HSSFFont font) throws NestableException { HSSFCell cell = HSSFCellUtil.createCell(row, col, null); if (value == null) { return;// w ww. j a va 2 s. c o m } if (font != null) { HSSFCellStyle style = workbook.createCellStyle(); style.setFont(font); cell.setCellStyle(style); } switch (formatType) { case TEXT: cell.setCellValue(value.toString()); break; case INTEGER: cell.setCellValue(((Number) value).intValue()); HSSFCellUtil.setCellStyleProperty(cell, workbook, CellUtil.DATA_FORMAT, HSSFDataFormat.getBuiltinFormat(("#,##0"))); break; case FLOAT: cell.setCellValue(((Number) value).doubleValue()); HSSFCellUtil.setCellStyleProperty(cell, workbook, CellUtil.DATA_FORMAT, HSSFDataFormat.getBuiltinFormat(("#,##0.00"))); break; case DATE: cell.setCellValue((Date) value); HSSFCellUtil.setCellStyleProperty(cell, workbook, CellUtil.DATA_FORMAT, HSSFDataFormat.getBuiltinFormat(("m/d/yy"))); break; case MONEY: cell.setCellValue(((Number) value).intValue()); HSSFCellUtil.setCellStyleProperty(cell, workbook, CellUtil.DATA_FORMAT, format.getFormat("($#,##0.00);($#,##0.00)")); break; case PERCENTAGE: cell.setCellValue(((Number) value).doubleValue()); HSSFCellUtil.setCellStyleProperty(cell, workbook, CellUtil.DATA_FORMAT, HSSFDataFormat.getBuiltinFormat("0.00%")); } if (bgColor != null) { HSSFCellUtil.setCellStyleProperty(cell, workbook, CellUtil.FILL_FOREGROUND_COLOR, bgColor); HSSFCellUtil.setCellStyleProperty(cell, workbook, CellUtil.FILL_PATTERN, HSSFCellStyle.SOLID_FOREGROUND); } }