Generating jasper report in xls
Below is the code for generating report in xls by using jasper framework.
List dataList = new ArrayList();
Map productMap = new HashMap();
productMap.put("product_id", "1001");
productMap.put("product_name", "Product 1");
dataList.add(productMap);
productMap = new HashMap();
productMap.put("product_id", "1002");
productMap.put("product_name", "Product 2");
dataList.add(productMap);
JRBeanCollectionDataSource jrBeanCollectionDataSource = new JRBeanCollectionDataSource(dataList);
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, new HashMap(), jrBeanCollectionDataSource);
OutputStream ouputStream = new FileOutputStream(new File("C:/JasperReports/prod_detail.xls"));
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
JRXlsExporter exporterXLS = new JRXlsExporter();
exporterXLS.setParameter(JRXlsExporterParameter.JASPER_PRINT, jasperPrint);
exporterXLS.setParameter(JRXlsExporterParameter.OUTPUT_STREAM, byteArrayOutputStream);
ouputStream.write(byteArrayOutputStream.toByteArray());
ouputStream.flush();
ouputStream.close();
Related Post
Comments
Leave a Reply