InetSoft How-To: Exporting Dashboards Dashboards Programmatically

Rich Text Format (RTF) is an ASCII based file format that can be used to store documents with style information. It is readable by most word processors to allow editing of the contents. The InetSoft Builder class supports exporting a file to RTF format.

The RTF format does not have as many layout options as Style Intelligence has. Therefore the generated RTF file will not always capture the complete format information of a report. However, all report data, including text, table and image (painters), is saved in the RTF file.

The main purpose of exporting a report to an RTF file is for further human manipulation of the report information, rather than for printing. Therefore, the loss of report formatting information is not critical in most instances. If the purpose of saving a report is only for later viewing, PDF or Postscript files would be a much better choice.

#1 Ranking: Read how InetSoft was rated #1 for user adoption in G2's user survey-based index Read More

Creating an RTF file follows the same procedure as saving a report file. We first obtain a Builder object for the RTF export and then write the report to the output file:

 FileOutputStream os = new FileOutputStream(filename);
 Builder builder = Builder.get
 Builder(Builder.RTF, os);
 builder.write(sheet); os.close(); 

Another option is to export to RTF layout format, using Builder.RTF_LAYOUT to get the Builder object. This format conforms more precisely to the layout of the report. However, since elements are placed in blocks in the generated file, they may be harder to edit in some instances.

Exporting to Delimited Text File (CSV)

One use for report data is to load the table data into another program, such as a spreadsheet, to be manipulated further. This is similar to the purpose of RTF files, except that RTF files are manipulated with word processors, whereas table data is manipulated with spreadsheet applications.

For the intended use of exporting delimited text files, only the table data is normally useful. To support the exporting of report table data, a CSV formatter is supplied in the inetsoft.report.io package. Only table data is exported to the text file. If there is more than one table in the report, they are exported to the file one by one. By default, the exported file is delimited by commas (CSV).

FileOutputStream os = new FileOutputStream(filename);
Builder builder = Builder.getBuilder(Builder.CSV, os);
builder.write(sheet);
os.close();

Use the DelimitedFormatter class directly to change the delimiter character. The following code segment changes the delimiter to a tab and quotes each field with a double quote.

FileOutputStream os = new FileOutputStream(filename);
DelimitedFormatter fmt = new DelimitedFormatter(os);
fmt.setDelimiter("\t");
fmt.setQuote("\"");
Builder builder = new Builder(fmt);
builder.write(sheet);
os.close();

Summary of Dashboard and Report Export Options

During this chapter we have described how to save and export a report in a variety of file formats. For PDF generation, we need to be aware of font discrepancies between the operating system and the PDF fonts. We described several methods for dealing with this issue, including changing a base-14 font, mapping, and embedding fonts within the document. We also described how to create a PDF document with CJK (Chinese, Japanese, Korean) characters, which requires that the PDF generator be aware of the mapping between the OS fonts and the PDF fonts. We also described how to export reports to various file formats including Excel, HTML, RTF and CSV. The process is very similar in each case and involves first creating a FileOutputStream and then using the Builder class to export the report in the required format on the output stream.

Previous: Exporting Dashboards and Reports to HTML