Introduction
I have been able to extend JRXlsExporter.java to provide my own implementation that utilizes Apache POI library. You can further add more formatting details to it according to your needs. In addition, you can configure your jrxml by adding the following custom property.
Jasper Report jrxml Custom Property:
I also introduce a new feature to JasperReports v5.0.1 with the following custom property for repeating rows. The following line needs to be added to each Jasper report that needs to have repeating rows, if we don’t add the following line then I have already introduced the default to be 2:4 repeating rows.
<property name="net.sf.jasperreports.export.xls.repeating.rows.range" value="1:4" />
Please let me know if you need additional details
Modified JRXlsExporter.java
/** * @author ANWAR_K * * This is a custom implementation of JRXlsExporter class that allows * for providing custom JRXlsExporter implementation in order to provide * extra features that is not supported by the default JRXlsExporter class. */ package osh.bls.gov.jasperreports.engine.export; import org.apache.poi.ss.util.CellRangeAddress; import net.sf.jasperreports.engine.JRPropertiesUtil; import net.sf.jasperreports.engine.JasperReportsContext; import net.sf.jasperreports.engine.export.JRXlsExporter; public class CustomJRXlsExporter extends JRXlsExporter { /** * Custom Property used to store the range of repeating rows for the sheet. */ public static final String PROPERTY_REPEATING_ROWS_RANGE = JRPropertiesUtil.PROPERTY_PREFIX + "export.xls.repeating.rows.range"; /** * */ public CustomJRXlsExporter() { super(); } /** * @param jasperReportsContext */ public CustomJRXlsExporter(JasperReportsContext jasperReportsContext) { super(jasperReportsContext); } /** * @param name */ protected void createSheet(String name) { super.createSheet(name); // Set the rows to repeat from range1 to range2 on the first sheet. String repeatingRowsRange = getPropertiesUtil().getProperty(jasperPrint, PROPERTY_REPEATING_ROWS_RANGE) == null ? "2:4" : getPropertiesUtil().getProperty(jasperPrint, PROPERTY_REPEATING_ROWS_RANGE); sheet.setRepeatingRows(CellRangeAddress.valueOf(repeatingRowsRange)); } }
Recommended Comments