Java Reference
In-Depth Information
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JRExporterParameter;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.export.JRHtmlExporter;
import net.sf.jasperreports.engine.util.JRLoader;
public class HtmlExportDemo
{
public static final String REPORT_DIRECTORY = "reports";
public void htmlExport(String reportName)
{
File file = new File(REPORT_DIRECTORY + "/" + reportName +
".jrprint");
try
{
JasperPrint jasperPrint = (JasperPrint)
JRLoader.loadObject(file);
JRHtmlExporter htmlExporter = new JRHtmlExporter();
htmlExporter.setParameter(JRExporterParameter.
JASPER_PRINT, jasperPrint);
htmlExporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME,
REPORT_DIRECTORY + "/" + reportName + ".html");
System.out.println("Exporting report...");
htmlExporter.exportReport();
System.out.println("Done!");
}
catch (JRException e)
{
e.printStackTrace();
}
}
public static void main(String[] args)
{
new HtmlExportDemo().htmlExport(args[0]);
}
}
In this example, we generate an HTML file and save it to disk. The JRExporter
implementation for HTML export is net.sf.jasperreports.engine.export.
JRHtmlExporter . Just as in previous examples, we set the report to export and the
file name by setting the appropriate parameters.
 
Search WWH ::




Custom Search