G - Format

Prev Next

Overview

Before saving the results, consider shaping up the data as you need present. This includes arranging the data you want to output, and adding some color and style for Excel files, HTML, etc.

Sorting and Rearranging the Data


table sort rows() Sort table rows by alphabetic, numeric, date orders, etc.
table sort selected rows() Sort only specific rows and leave all other rows unchanged.
table sort columns() Sort table columns accordingly.
table rearrange columns() Rearrange columns in desired orders, all other columns are further to the right
table rearrange selected rows() Rearrange rows in desired orders
table substitute horizontally()
table substitute vertically()
Replace repeating values with simple remarks, like " or dito.



Add Style and Colors to Spruce up your Tables

If you plan to save the work in Excel (or HTML), then consider adding styles such as applying colors, different typefaces, freezing the header row, adjusting column width, applying autofilters, etc.


table style auto width() Adapts the column widths based on the lengths of the contents.
table style theme() Applies a graphic color theme on the table, e.g. highlighted header row and zebra pattern in the rows below for better readability
table style table() Apply overall table formats, e.g. autofilter row, freezing panes, default character sets, etc.
table style rows() Apply styles for selected rows, e.g. highlighting them with colors, underlining, etc.
table style columns() Apply styles for selected columns, e.g. specific number and date formats, highlighting of any kind, etc.
table style cells() Apply styles for indiviual cells or groups of cells, e.g. highlighting specific values.



Wikipedia Example (continued from step 6)

Do some validation on this table:

  • Set column widths
  • Set appropriate number formats
  • Freeze the top row and activate the autofilter feature
  • Histogram: Apply color accents for the values, aiming to improve visualization

Simple Example


table sort selected rows        ( c1, [Country]{0..3}!="All ", Country );
                                // Sort all country names, but leave continents at the bottom

table style auto width          ( c1 );
table style columns             ( c1, Area, sheet, column width, 16 );
table style columns             ( c1, {Area, Population},    table, number format, "#,##0");
table style columns             ( c1, Inhabitants Variation, table, number format, "0.00%");
table style columns             ( c1, Inhabitants per km2,   table, number format, "#,##0.00");
table style table               ( c1, sheet, freeze rows, 1, autofilter, 0 );
table style rows                ( c1, 0, table, boldface, true );

table style table               ( histo, sheet, column width, 10 );
table style columns             ( histo, 0, sheet, column width, 20, boldface, true );
table style rows                ( histo, 0, table, boldface, true, row height, 30 );
table style cells               ( histo, 0, 0, single, wrap text, true );

table process cells             ( histo, if (col()>0)
                                  {
                                      shade[] = limit(255-10*[.],0,255);
                                      table style cells( histo, col(), row(), single, fill color, {shade[],255,shade[]});
                                  } );
The table has been formatted.
Try it yourself: Open TAB_Features_Format_the_results.b4p in B4P_Examples.zip. Decompress before use.