rakesh-singh.deo Posted March 29, 2018 Share Posted March 29, 2018 I want to create 2 csv files from one action event "(on submit button) from jasper reports. Used 2 template for 2 jasperdesign(2 different jrxml file.I am able to generate 2 separate csv reports with two action . but i am not able to genarte 2 csv Reports at a time.1.Export_AdminUser_Authentication_29-03-2018 18_50_35.csv2.export_AdminUser_Authorization_29-03-2018 10_31_03.csvI have using this code...JRDataSource jrDataSource = new JRBeanCollectionDataSource(updatedenTrnListBean(genTrnListBeanLocal , genTrnListBean)); JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign); JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport,mapParameter, jrDataSource); ByteArrayOutputStream bos = new ByteArrayOutputStream(); if(JASPER_REPORT_TYPE_EXCEL.equals(reportType)){ /// Generate XL File fileExtention = ".xlsx"; JRXlsxExporter exporter = new JRXlsxExporter(); exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint); exporter.setParameter(JRXlsExporterParameter.IS_WHITE_PAGE_BACKGROUND, Boolean.FALSE); exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, bos); if(genericFilterCriteria.getTransactionType().equalsIgnoreCase("ifmAuthentication")){ exporter.setParameter(JRXlsExporterParameter.SHEET_NAMES, new String[] {"ifmAuthentication"}); } if(genericFilterCriteria.getTransactionType().equalsIgnoreCase("ifmAuthorization")){ exporter.setParameter(JRXlsExporterParameter.SHEET_NAMES, new String[] {"ifmAuthorization"}); } exporter.exportReport(); }else if(JASPER_REPORT_TYPE_CSV.equals(reportType)){ /// Generate CSV File fileExtention = ".csv"; JRCsvExporter exporterCsv = new JRCsvExporter(); exporterCsv.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint); exporterCsv.setParameter(JRExporterParameter.OUTPUT_STREAM, bos); // exporterCsv.setParameter(JRCsvExporterParameter.fi, sheetNames); if(genericFilterCriteria.getTransactionType().equalsIgnoreCase("ifmAuthentication")){ exporterCsv.setParameter(JRXlsExporterParameter.SHEET_NAMES, new String[] {"ifmAuthentication"}); } if(genericFilterCriteria.getTransactionType().equalsIgnoreCase("ifmAuthorization")){ exporterCsv.setParameter(JRXlsExporterParameter.SHEET_NAMES, new String[] {"ifmAuthorization"}); } exporterCsv.exportReport(); } Link to comment Share on other sites More sharing options...
Solution hozawa Posted March 29, 2018 Solution Share Posted March 29, 2018 Don't know what the problem is. Can't you just create a method to generate csv file and call it twice in 1 submit action? Link to comment Share on other sites More sharing options...
rakesh-singh.deo Posted March 30, 2018 Author Share Posted March 30, 2018 I am able to do it but for CSV file I am not getting multiple sheets inside the single workbook/file.And the sheet name for CSV sheet also not reflected as I put it. String fileName="TESTReport1"; fileExtention = ".csv"; JRCsvExporter exporterCsv = new JRCsvExporter(); exporterCsv.setParameter(JRExporterParameter.JASPER_PRINT_LIST, jprintlist); exporterCsv.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, fileName); exporterCsv.setParameter(JRExporterParameter.OUTPUT_STREAM, bos); exporterCsv.exportReport(); } //String fileName="TESTReport"; Calendar cal = Calendar.getInstance(); String time = CFMUtils.convertDateTimeToString(cal.getTime()).replace( ":", "_"); String fileName=""; if(genericFilterCriteria.getTransactionType()==null){ fileName = new StringBuilder("Export_") .append(loggedUser.getLogin()).append("_").append(time) .append(fileExtention).toString(); fileName = fileName.replaceAll(">[ n]*<", "_"); } else{ fileName = new StringBuilder("Export_") .append(loggedUser.getLogin()).append("_"+genericFilterCriteria.getTransactionType()).append("_").append(time) .append(fileExtention).toString(); fileName = fileName.replaceAll(">[ n]*<", "_"); } InputStream is = new ByteArrayInputStream(bos.toByteArray()); return new ExcelStreamResponse(is, fileName);Above code is working fine for genertaing Excel report in njapser.But for sheet names and multiple sjeets in CSV its not working.Please suggest any additional changes neede. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now