Formatter trait
Resolver One supports various types of formatting that can be specified through the Format -> Number.. dialog. However, if you want to specify more complicated formatting, Resolver One also supports custom formatting through the Formatter trait.
The Formatter trait is a function that takes 2 arguments: the first is the value that is to be formatted and the second is the default formatter that would normally be used to format the value. You can override or enhance the formatting of a value by creating a function that applies the appropriate format to the value supplied:
workbook['Sheet1'].DecimalPlaces = 2 workbook['Sheet1'].Cells.A1.Formatter = lambda x, df: df(x) + 'km'
The example above uses the default formatter to format the value and then adds 'km' to the end of the resulting formatted string.
Formatters can also be applied to columns, rows and to entire worksheets:
def formatmm(value, defaultFormatter):
return defaultFormatter(value) + 'mm'
workbook['Sheet1'].Cols[2].Formatter = formatmm
workbook['Sheet1'].Rows[2].Formatter = lambda x, df: df(x) + 'cm'
workbook['Sheet2'].Formatter = lambda x, df: df(x) + 'kg'
The last Formatter specified in the code is the one that will be used for a particular cell.
Comments
If you have comments, questions or suggestions about any of the Resolver One documentation, please post them to the Documentation Suggestions Forum.
