Jump to content
Changes to the Jaspersoft community edition download ×
  • How to set Print Titles when exporting to Excel


    kamran21754_1
    • Features: Exporters Version: v5.0.1 Product: JasperReports® Library

    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));
      }
    }
    
    

     

    customjrxlsexporter.java


    User Feedback

    Recommended Comments

    Hello Anwar,

    We have the same requirement to be implemented. But we are uding Jasper library version 6.11.

    Do you by any chance have tried this with 6.11. The createSheet method is changed and we are unable to find the setRepeatingRows method. You advise in this regards is appreciated.

    super.createSheet(arg0, arg1); with two arguments

    sheet.setRepeatingRows - Not available

    Thanks,

    Abhishek

    Link to comment
    Share on other sites



    Guest
    This is now closed for further comments

×
×
  • Create New...