Using the Export Control to Deliver Reports in Other Formats

So far all the scenarios that have been discussed in this chapter have involved displaying reports in dynamic HTML format. Although this is a great report delivery method for most scenarios, there are times when reports need to be exported to various other file formats. Although this can be accomplished by using the ReportClientDocument object model, there is an easier way to do this: using the Export control.

Listing 32.10 shows how the Export control would be used to export a report to PDF. Notice that the Export control has the concept of the report source of the processHttpRequest method.

Listing 32.10. Exporting a Report via Code
//Instantiate a ReportExportControl object
ReportExportControl exportControl = new ReportExportControl();

//After you have created the ReportExportControl object, you must
//specify the export format that you want to export the report to. To
//specify the export format create an ExportOptions object:

ExportOptions exportOptions = new ExportOptions();

//Specify the export format by calling the ExportOptions object's
//setExportFormatType method, passing it the integer constant that
//represents the chosen format:
exportOptions.setExportFormatType(ReportExportFormat.PDF);

//To initialize an Export control in a Crystal Enterprise environment set
//the control's report source by calling its setReportSource method.exportControl
.setReportSource(reportSource);

//Call the control's setExportOptions method, passing it an ExportOptions object
exportControl.setExportOptions(exportOptions);

//You may also want to call the setExportAsAttachment method, passing it the
//Boolean value true. The Export control will then display a dialog box
//that allows users of your Web application to save the exported report before
//they open it: exportControl.setExportAsAttachment(true);

//To initialize an Export control in an unmanaged RAS environment set the
//control's report source by calling its setReportSource method and passing
//the method a reference to a report source object.
exportControl.setReportSource(reportSource);

//Call the control's setExportOptions method, passing it an ExportOptions object
exportControl.setExportOptions(exportOptions);

//You may also want to call the setExportAsAttachment method, passing it the
//Boolean value true. The Export control will then display a dialog box
//that allows users of your Web application to save the exported report before
//they open it:
exportControl.setExportAsAttachment(true);

//After you have created an export control, you call its processHttpRequest
//method to complete the export.
exportControl.processHttpRequest(request, response, getServletContext(), null) ;
					

Figure 32.5 shows a report being exported to PDF.

Figure 32.5. Using the Export control to export a report to PDF.


..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.14.251.57