Freeze panes with JRXlsExporter

Hi,


the "freeze panes" Excel functionality is available in POI, provided by the HSSFSheet. Fortunately, the JRXlsExporter's sheet attribute is protected. Hence, class JRXlsExporter can be subclassed in order to expose the "freeze panes" functionality, see the code below.
 

I'm still searching for the way to do the same when using class JExcelApiExporter instead of class JRXlsExporter, I'll post if I found.
Any idea is welcome, thanks for your attention.
Tangi
 

Code:
package my.jasperreports.engine.export;
 
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<String, int[]> panes;
 
	public XlsExporter()
	{
		super();
		this.panes = new HashMap<String, int[]>();
	}
 
	/**
	 * This overriding method is in charge of creating and freezing a pane.
	 * @param	name	sheet name being created
	 */
	@Override
	protected void createSheet( String name )
	{
		super.createSheet( name );
		int[] pane = this.panes.get( name );
		if( pane != null )
		{
			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 )
	{
		this.panes.put( sheetName, new int[] { colSplit, rowSplit } );
	}
}
</td></tr></tbody></table>
tangi's picture
109
Joined: May 7 2009 - 1:36am
Last seen: 14 years 4 months ago

0 Answers:

No answers yet
Feedback