Since 4D v16 R4, it’s been possible to create tables by programming in your 4D Write Pro documents. Styling the whole table or just certain cells could be done during the creation of the document, but maybe you also want to manage your tables afterwards. Now, it’s easy to manipulate tables in an existing document, to change the border style or color, to change the font size or make it bold, etc.
4D Write Pro programming is highly based on “ranges“. After paragraph ranges and picture ranges, 4D v17 introduces a new type of range: table ranges, returned by a new command: WP Create table range. Styling tables is now simple with this new command and new type of range!
Create a table range
Similar to the existing WP Create paragraph range and WP Create picture range commands, WP Create table range returns a range that addresses only the tables contained in the range passed as parameter. The input parameter can be either a document, an element (header, body, footer, etc.) or any other range.
Check out our example database to learn more about this command, as well as the new commands, WP Get elements and WP Get element by ID, introduced in this blog post.
code example
The following example demonstrates how to create a range containing all of the tables in an existing document. Once created, the range can be used to style the tables and their content using standard 4D Write Pro attributes.
// Load an existing document containing tables
wpDoc:=[CUSTOMERS]document
tableRange:=WP Create table range(wpDoc)
// Style all tables in the document: style border, cell background color, cell text font size, etc.
WP SET ATTRIBUTES(tableRange;wk border style;wk solid;wk border color;"Blue";wk border width;"3px")
WP SET ATTRIBUTES(tableRange;wk background color;"#f0f0ff")
WP SET ATTRIBUTES(tableRange;wk table align;wk center)
WP SET ATTRIBUTES(tableRange;wk font size;12)
WP SET ATTRIBUTES(tableRange;wk text transform;wk capitalize)