Annotate member variables or methods that will appear on the report
@Reportable(headerName = "Name", column = "A")
@ReportableMap Map<String, Object> map
The map's key will be the headerName
Note: The map field must use a LinkedHashMap (or another ordered Map implementation) to guarantee deterministic column ordering. Using a HashMap will produce non-deterministic column order in the generated report.
Map values can be a boxed primitive or String (rendered as a single column, as above), or a complex object annotated with @Reportable members — in which case each entry expands into one column per @Reportable field/method on the value's class, and the map key becomes a single header spanning those columns.
public class User {
@Reportable(headerName = "First Name", column = "A")
private String firstName;
@Reportable(headerName = "Last Name", column = "B")
private String lastName;
@Reportable(headerName = "Salary", column = "C")
@NumberFormatter(format = "#,##0.00")
private double salary;
}
public class Team {
@Reportable(headerName = "Team", column = "A")
private String teamName;
@ReportableMap
private LinkedHashMap<String, User> users;
}
Given a Team with users = {"Primary": User("Alice", "Smith", 500.5)}:
Team | Primary with Primary merged across the 3 generated columns, and the data row is <team name> | Alice | Smith | 500.50 — with Salary rendered as a formatted numeric cell via @NumberFormatter, exactly as it would be for a top-level @Reportable field.Team,Primary,, <team name>,Alice,Smith,500.50
Each nested member's own formatting annotations (@DateFormatter, @NumberFormatter, @StringFormatFormatter, @StringFormatter, @CurrencyFormatter, @BooleanFormatter, @NullFormatter, @CommaFormatter, @TrimFormatter) are applied the same way they would be on a top-level @Reportable field.
If a value's class has no @Reportable-annotated members (for example an unannotated object or a java.util.Date), the entry falls back to the original single-column behavior, rendered via toString().
Note: As with top-level fields, the columns generated for each map key are determined from the first data row's map. If a later row's map is missing an entry for that key, or the entry is null, the corresponding cells are simply left blank rather than shifting the remaining columns.
Annotate reportable member variables or methods with formatters (optional)
@DateFormatter(format = "yyyy-MM-dd") @NumberFormatter(format = "#,##0.00") @StringFormatFormatter(text = "Add %s text") @StringFormatter(format = Format.UPPERCASE) @CurrencyFormatter(format = Currency.USD) @BooleanFormatter(falseText = "Not Valid", trueText = "Valid") @NullFormatter(replacementText = "No Data") @CommaFormatter @TrimFormatter
Instantiate and generate
new CSVGenerator(List<?> data, char delimiter).generate(); // returns CSV String new ExcelGenerator(List<?> data).generate(); // returns POI Workbook
Passing an empty list produces an empty report — no data rows are written. CSV and Excel output will contain headers only.
@AutoSize @Reportable(headerName = "Name", column = "A")
AutoSize coupled with Reportable will set the Excel columns to auto-adjust with column width to fit content
@DateFormatter(format = "yyyy-MM-dd")
Data types supported
Format used by java.text.SimpleDateFormat
@NumberFormatter(format = "#,##0.00")
Data types supported
Format used by java.text.DecimalFormat
@StringFormatFormatter(text = "Add %s text")
Data types supported
@StringFormatter(format = Format.UPPERCASE)
Data types supported
Options
@CurrencyFormatter(format = Currency.USD)
Data types supported
Options
@BooleanFormatter(falseText = "Not Valid", trueText = "Valid")
Arguments
@NullFormatter(replacementText = "No Data")
Data ytpes supported
Arguments
@CommaFormatter
Data types supported
@TrimFormatter
Data types supported
@Hyperlink
Creates a hyperlink out of the cell data
Note: Only applies to ExcelGenerator