Exporting to Excel

It is not uncommon to request reports in Microsoft Excel format as Excel allows easy manipulation of report data to perform calculations. JasperReports provides built-in capability to export reports to Excel. The following example demonstrates this functionality:

package net.ensode.jasperbook;

import java.io.File;

import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JRExporterParameter;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.export.JExcelApiExporter;
import net.sf.jasperreports.engine.util.JRLoader;

public class XlsExportDemo
{
  public static final String REPORT_DIRECTORY = "reports";
  public void xlsExport(String reportName) { File file = new File(REPORT_DIRECTORY ...

Get JasperReports 3.5 for Java Developers now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.