Java Reference
In-Depth Information
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.export.JRXlsExporter;
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 + "/" + reportName +
".jrprint");
try
{
JasperPrint jasperPrint = (JasperPrint)
JRLoader.loadObject(file);
JExcelApiExporter xlsExporter = new JExcelApiExporter();
xlsExporter.setParameter(JRExporterParameter.
JASPER_PRINT, jasperPrint);
xlsExporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME,
REPORT_DIRECTORY + "/" + reportName + ".xls");
System.out.println("Exporting report...");
xlsExporter.exportReport();
System.out.println("Done!");
}
catch (JRException e)
{
e.printStackTrace();
}
}
public static void main(String[] args)
{
new XlsExportDemo().xlsExport(args[0]);
}
}
This example follows the same pattern as the previous examples in this chapter. The
JRExporter implementation needed to export to Excel is net.sf.jasperreports.
engine.export.JExcelApiExporter . Again, we set the report to export and the
output file name by setting the appropriate parameters on JExcelApiExporter .
 
Search WWH ::




Custom Search