Cell formatting

by Tom Moore , March 19, 2020

Patchworks makes a best effort to effectively format the data values that are shown in reports. The basic method is to provide a level of precision appropriate for the magnitude of the numbers involved. But in some cases a different format can make a better data representation, and this is where custom formats come in handy.

Custom cell formats are applied to every data cell in a report table, and they can control the number of trailing digits after the decimal point, the use of a grouping character between thousands, as well as special prefix and suffix characters.

Cell formats are specified using the 'setDisplayFormat' method that is available with every report type. The argument to the method is a string value that uses the same codes as the Java DecimalFormat class. For example, the pattern "$###,###,###" means to use a dollar sign prefix, no leading zeros, no fractional values, and a comma separator after the million and thousand columns.

It is easy to apply a custom cell format, as can be seen in this simple example:

expressions4 = new String[] {

labels5 = new String[] {

report1 = new PeriodExpressionReport("training/trans", // filename
    "Transportation Costs", // title
    "$", // units
    control.getNetworkTable(), // attributeStore
    "", // reselectExpression
    Horizon.activeList, // periods
    false, // annualize
    "", // HTMLText
    false, // percent
    expressions4, // expressions
    labels5 // labels

The resulting data table is easier to read and provides a stronger visual cue for the interpretation of the content.