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

Creating report in java using jasper
javax.servlet.ServletException: javax.naming.NameNotFoundException: Name comp is not bound in this Context
More than one value of type [net.sf.jasperreports.engine.JRDataSource] found
NoClassDefFoundError: com/lowagie/text/DocumentException
nested exception is java.lang.NoClassDefFoundError: org/apache/poi/hssf/usermodel /HSSFCellStyle

Comments

Leave a Reply