Search Locate Previous Next Contents

Formatting Data in a Table

By default, NewLeaf applies the primitive thorn function () to each element of a table to ensure that it is text. It is possible to format the contents of one or more columns by providing NewLeaf with a vector of format specifications. Each of these must be a valid left argument to the ŒFMT system function. Format the sales data table by typing:

leaf.Init ª leaf.Use''
leaf.table.Qfmt 'CF8.1'
leaf.table.List salesQ1
View doc„leaf.Close

NewLeaf treats a simple format specification as if it were a one-element vector of vectors. It reshapes the vector of format specifications to match the number of columns in the table; try the previous example using (›''),›'CF8.1'. NewLeaf does not override the behaviour of ŒFMT. For example, where a value overflows the number of characters allowed by the format specification, a series of asterisks appears in that cell of the table. You are likely to find that this has occurred to the grand total in the bottom right corner of the table. To correct this, provide a separate format specification for each column and increase the field width in the format specification for the rightmost column:

leaf.Init ª leaf.Use''
leaf.table.Qfmt ((¯1+¯1†½salesQ1)½›'CF8.1'),›'CF9.1'
leaf.table.List salesQ1
View doc„leaf.Close

For columns containing alphanumeric strings, it is best to ensure that each string is a vector and to allow NewLeaf to apply the default formatting. Whenever an empty vector is found in the vector of format specifications, NewLeaf applies the thorn function to the contents of the corresponding column. Now you can begin to write the code that will create the body of the one-page sales report:

leaf.Init ª leaf.Use''
leaf.table.Qfmt (›''),((¯1+¯1†½salesQ1)½›'CF8.1'),›'CF9.1'
leaf.table.List products,salesQ1
View doc„leaf.Close


Continue to: Horizontal Alignment within Table Columns
© Copyright Causeway Graphical Systems Ltd 2001