table style theme
Style Library
This function provides a nice all-in-one formatting which converts the raw table into a nicely formatted table with emphasized header rows, frames and (zebra style) shading patterns, etc, whatever is requested. This function accesses an Excel table (B4P Style Themes.xlsx, located in the directory where the B4P libraries) which describes a few basic styling themes:
Theme Name | Brief Description |
---|---|
Plain ... | White table |
Gnu ... | Headers emphasized with a fill color and white table below |
Zebra ... | Headers like above, and adjacent white and shaded table data rows below |
Quagga ... | Like Zebra, but two different shades are used for the data rows, instead of white |
... | Theme names used alone result in no border lines applied |
... Horizontal Lines | Horizontal lines are drawn above and below every row |
... Vertical Lines | Vertical lines are drawn on left and right side of every column |
... Gridlines | Combination of horizontal and verical lines |
All theme names are case sensitive. Additional theme names can be added to the theme table, but this is only advisable to
more experienced B4P users. Instructions are specified in the Excel file. (In case you don't know what Quaggas are: They are extinct horse-like
animals of darker colors with some zebra like fur patterns, but these patters do not fulfill the great job to keep mosquitos away by irritating
their limited vision. Unfortunately, humans and not the insects made them extinct.)
This function does not address the column widths. Instead, call the function table style auto width() in addition to this function
to set the column widths in an easiyl readable form.
A simpler alternative to editing the Excel file is to provide additional parameters to the function call, which are formulated in pairs of
two consecutive parameters: attribute names and attribute values. You can add further formatting, change theme colors, and do all kind of
adjustments and enhancements. Following attributes are supported where all attribute values must be provided as strings, with exception for
attribute name pattern where numerals are expected instead.
Attribute Name | Attribute Value | Description |
---|---|---|
border color | Color, see 1 | Defines the principial border color. (In the Excel file, this value is available as variable 'border color[]') |
fill color | Numeral: 1..255 | Defines the principial fill color. (In the Excel file, this value is available as variable 'fill color[]'). For both border and fill color, the style theme description may use different intensities or shades of the color specified. |
sheet | Attribute names and values | Put one or multiple pairs of attribute names and values, separated by commas, into a string. The attributes are specified in the same way as for table style table() applied on the whole sheet. Example: "autofilter, 0, freeze rows, 1" to set autofiter row and freeze the first row. |
table | Attribute names and values | Put one or multiple pairs of attribute names and values, separated by commas, into a string. The attributes are specified in the same way as for table style table() applied on the table. Example: "autofilter, 0". |
frame | Border specification | If you want a frame added around the whole table, then specify the attribute value for a border which is a set containing thickness and color, but must be put into a string. |
pattern | Value (numeral type expected) | If used in conjunction with attribute names Zebra ... or Quagga ..., then this value rules the width of the zebra pattern, i.e. number of adjacent rows with same fill color. Example: table style theme( my table, Quagga, pattern, 2 ); for 2 rows in one color and next 2 rows in a different color. |
rule 0, 1, .. | Expression returning Boolean | Specify the condition which rules whether the corresponding style 0, 1, ... shall be applied or not. Adding a " >>" (space followed by 2 greater-than symbols) indicates checking does not stop here if true, but continue checking the next rules. Highly advised to specify rule 0 combined with style 0 to format the header row(s). |
style 0, 1, .. | Attribute names and values | Put one or multiple pairs of attribute names and values, separated by commas, into a string. The attributes are specified in the same way as for table style rows(). |
1 Specify the the color either by supported color name (e.g. rad, orange, chestnut, navy, etc.), hexadecimal value (e.g. "#FF8040") or set containing three values, but must be converted to a string in this case (e.g. "{255,128,64}" ).
This function is in beta stage. Exect further developments to happen
Don't forget to include 'Style Library' at the top of your program
2, 4, 6, 8, etc.
No. | Type | Description |
---|---|---|
1. input |
string | Name fo existing table |
1. input |
string | Theme name A supported theme name must be specified, Example: "Zebra", or "Zebra Vertical Lines". Theme names are case sensitive. |
Opt. 3, 5, ... input |
string | attribute name See table above for supported attribute names. |
Opt. 4, 6, ... input |
string | attribute value See table above for supported attribute values. |
table load ( t, "Examples\Cities.csv" );
themes[] = list themes(); // List will also be shown on the screen
// Plain Vanilla approach
for all parameters( themes[], theme[], i[] )
{
table copy table ( t, theme[] );
table style theme ( theme[], theme[] );
table style auto width ( theme[]);
}
table save excel file( themes[], themes[], "Images\Style_Themes_Examples_1.xlsx" );
table style reset;
some colors[] = { burgundy, ocre, forest, navy };
// Fruits and extra toppings added
for all parameters( themes[], theme[], i[] )
{
color[]= some colors[]{mod(i[], 4)};
table copy table ( t, theme[] );
table style theme ( theme[], theme[],
pattern, 2, // Make zebra pattern wider
table, "text color, chestnut",
fill color, color[], // Vary fill colors
frame, "{ thick, gray 4 }", // Apply a frame around the table
sheet, "freeze rows, 1, autofilter, 0" ); // Freeze header, add autofilter feature
table style columns ( theme[], Inhabitants, body, number format, "#,###" );
table style auto width ( theme[]);
}
table save excel file( themes[], themes[], "Images\Style_Themes_Examples_2.xlsx" );
echo("Done");
Plain
Plain Horizontal Lines
Plain Vertical Lines
Plain Gridlines
Gnu
Gnu Horizontal Lines
Gnu Vertical Lines
Gnu Gridlines
Zebra
Zebra Horizontal Lines
Zebra Vertical Lines
Zebra Gridlines
Quagga
Quagga Horizontal Lines
Quagga Vertical Lines
Quagga Gridlines
Saved table(s) to EXCEL file 'Images\Style_Themes_Examples_1.xlsx' containing 16 sheets.
Saved table(s) to EXCEL file 'Images\Style_Themes_Examples_2.xlsx' containing 16 sheets.
Done
Test Click on the file name open the file with Excel (.xlsx) : Style_Themes_Examples_1.xlsx (plain vanilla), and
and Style_Themes_Examples_2.xlsx (fruits and extra toppings added).