Thursday, July 16, 2009

FreezingPanes in Excel -Jasper Report

Create a class like this..

import java.util.HashMap;
import java.util.Map;

import net.sf.jasperreports.engine.export.JRXlsExporter;

* Natively, the JRXlsExporter does not allow to freeze panes in Excel sheets.
* This class bypasses the JasperReports API and addresses directly to the POI
* API to freeze panes.
* @author TME
public class XlsExporter extends JRXlsExporter
private Map panes;

public XlsExporter()
this.panes = new HashMap();

* This overriding method is in charge of creating and freezing a pane.
* @param name sheet name being created
protected void createSheet( String name )
super.createSheet( name );
System.out.println("panes map"+this.panes);
this.sheet.createFreezePane( 2, 0 );
//int[] pane = (int[]) this.panes.get( 0 );
// System.out.println("pane array"+pane[0]);
/*if( pane != null )
{System.out.println("Inside if..");
//this.sheet.createFreezePane( pane[0], pane[1] );
*/ }

* Defines a pane to create and freeze in the specified sheet.
* @param sheetName sheet on which the pane is to be created
* @param colSplit column whose right side is split limit (0: no split)
* @param rowSplit row whose bottom side is split limit (0: no split)
public void freezePane( String sheetName, int colSplit, int rowSplit )
System.out.println("Inside freeze panes()");

this.panes.put( sheetName, new int[] { colSplit, rowSplit } );


Call the function
In the generateXL() function u have…
XlsExporter xlsExporter=new XlsExporter()

Try following the link:

1 comment:

  1. Great Nikkie !!!!!!!!!!
    It would be good if you can list out the jar needed for this.