Java Reference
In-Depth Information
{
JasperPrint jasperPrint = (JasperPrint)
JRLoader.loadObject(file);
JRCsvExporter csvExporter = new JRCsvExporter();
csvExporter.setParameter(JRExporterParameter.
JASPER_PRINT, jasperPrint);
csvExporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME,
REPORT_DIRECTORY + "/" + reportName + ".csv");
System.out.println("Exporting report...");
csvExporter.exportReport();
System.out.println("Done!");
}
catch (JRException e)
{
e.printStackTrace();
}
}
public static void main(String[] args)
{
new CsvExportDemo().csvExport(args[0]);
}
}
Again, this example follows the same pattern we have seen in previous examples.
The JRExporter implementation used to export to CSV is net.sf.jasperreports.
engine.export.JRCsvExporter . The report to export and the file name of the
exported report are set by assigning the appropriate values to the
JRExporterParameter.JASPER_PRINT and JRExporterParameter.OUTPUT_FILE_
NAME parameters.
The above code will generate a CSV file that looks like the following:
Aircraft registered in MD,,,,,,,,,,,,,
CHALLENGER II,,CL-600-2B16,,TOTAL,,,,,,,
SEVERNA PARK,,1,,0,,1,,,,,,
SPARKS,,0,,1,,1,,,,,,
TOTAL,,1,,1,,2,,,,,,
Aircraft registered in NY,,,,,,,,,,,,,
C90A,,CGS HAWK,,CH 2000,,CHALLENGER II,,CL-600-2B16,,COZY MARK IV,
BROOKLYN,,0,,0,,0,,0,,0,,1
HOLLEY,,0,,0,,0,,1,,0,,0
 
Search WWH ::




Custom Search