HOME > SUPPORT > EXCEL GENERATION

Excel and CSV Generation

 

Overview

ReportMill offers a simple means to generate Excel and CSV (comma separated value) reports. Like ReportMill's other output options, it's simply a matter of asking a report document for its Excel or CSV bytes:

// Get template and generate report as normal
RMDocument template = new RMDocument(aSource);
RMDocument report = template.generateReport(myJavaDataset, false);

// Now get Excel or CSV bytes
byte excelBytes[] = report.getBytesExcel();
byte csvBytes[] = report.getBytesCSV();

// Or simply write Excel or CSV to a file String

report.writeExcel("MyReport.xls");
report.writeCSV("MyReport.csv");

Dependencies (Excel only)

Excel generation depends on the OpenSource POI project (http://jakarta.apache.org/poi). We currently use the POI 3.0 jar. Since the jar is a little too big for our standard distribution (800k), we require developers to download it separately. You can download the complete POI distribution at the Apache site or here's a quick link to a version at ReportMill: http://www.reportmill.com/jars/poi30-rm.jar. This version is preferable, because it includes a bug fix implemented by ReportMill to fix the placement of graphics in a worksheet.

The Poi jar needs to be made available to your Java application in the same manner as the ReportMill jar (search your application server documentation for the phrase "Adding third party jars"). Generally this means adding the jar to your CLASSPATH or merging it into your application.

Also, the developer layout application offers a Preview Excel menu item. This will only work if the POI jar has been made available to the layout application. Since the layout application uses Java Web Start, you either have to add this to your Java extensions directory or you have to run the app from the commandline, including a reference to the POI jar:

prompt> java -cp ReportMill8.jar:poi30-rm.jar com.reportmill.App

Discrepancies

Unlike PDF, Flash and even HTML, neither Excel nor CSV come close to being page description formats. So developers should expect to get a data representation of the report - and not a WYSIWG representation. Because of this, using ReportMill to generate these files is somewhat of an overkill. You can often generate useful Excel and CSV files with a simple Java for loop with some StringBuffer appends. However, we understand the convenience of using ReportMill to generate these (and, of course, you get sorting, grouping and aggregating for free).

To get the best results for these output formats, you may want to create special, simpler versions of certain templates. In particular, these reports work best with tables containing structured rows (see the tables document for information on this).

Excel vs CSV

We recommend CSV whenever possible. This format is more generic and portable. However, Excel is nice because it retains basic font formatting (bold, italic) and relative column widths, and it may also save users the extra step of importing the CSV file.