Java Reference
In-Depth Information
The setParameter() method is used to set parameters used to export the report. In
most cases, two parameters need to be set: the jasperPrint object containing the
native report and the name of the output file or output stream used to output the
exported report. We would set the output file any time we are sure we want to save
the exported report to disk. We would set the output stream parameter for sending
the exported report through the network or when we are not sure if we want to save
the exported report to disk or stream it through the network. Since an output stream
can be easily saved to disk or streamed through the network, the decision can be
made at run time.
As can be seen in the given method signature, setParameter() takes an instance
of net.sf.jasperreports.engine.JRExporterParameter as its first argument.
JRExporterParameter contains a number of static constants that are typically used
as the first argument to setParameter() . To accommodate the most common cases,
the JRExporterParameter constants that are of interest are:
JRExporterParameter.JASPER_PRINT , used to set the JasperPrint object
to export
JRExporterParameter.OUTPUT_FILE_NAME , used to set the output file name
JRExporterParameter.OUTPUT_STREAM , used to set the output stream
There are several other constants defined in
JRExporterParameter . Consult the JavaDoc documentation
for JRExporterParameter at http://jasperreports.
engine/JRExporterParameter.html for details.
As we will see in the following sections, exporting to different formats follows the
same pattern in all cases. Once we are familiar with the procedure to export to one
format, learning to export to other formats will be trivial.
Exporting reports functionality is done entirely in Java code. The JRXML template
does not need to be modified at all. For most of the examples in this chapter, we will
be using the subdatasets example from the previous chapter.
Before moving on, it is worth mentioning that for most formats, exported reports
keep their formatting (fonts, colors, etc.). The only two formats that lose their
formatting are CSV and Plain Text, since both of these are plain text files containing
no formatting information.
Search WWH ::

Custom Search