Tech Tip: Change Cell Content Programmatically in 4D Write Pro
PRODUCT: 4D Write Pro | VERSION: 20 | PLATFORM: Mac & Win
Published On: December 18, 2024
A developer using 4D Write Pro may have a table that needs a certain value added to multiple of the same cell, or perhaps only one cell. In order to do this programmatically, the developer may use the following steps.
Given a table created something like this (the text values do not matter as they will be replaced):
WParea:=WP New() $table:=WP Insert table(WParea; wk append) $row:=WP Table append row($table; "Entry1"; "Entry2") $row:=WP Table append row($table; "row 2 here"; "2nd col of row 2") $row:=WP Table append row($table; "row 3 here"; "2nd col of row 3") $row:=WP Table append row($table; "row 4 here"; "2nd col of row 4") |
WP Table get cells can be used to pick which cells will be changed. The table is the first argument followed by the starting column, starting row, how many columns to select, and how many rows to select. The following selects starting at the first column and row and goes for 2 columns and 1 row.
$selected_cells:=WP Table get cells($table; 1; 1; 2; 1) |
Text content as well as attributes may be applies now that cells have been selected.
$range:=WP Text range($selected_cells; wk start text; wk end text) WP SET TEXT($range; "Sign-Ups"; wk replace) WP SET ATTRIBUTES($selected_cells; wk width; "3in") WP SET ATTRIBUTES($selected_cells; wk text color; "teal"; wk font bold; wk true; wk font size; "15pt") |
If the devloper wants to replace the content of one or more cells they may select those cells and replace the content and attributes the same way.
$selected_cells:=WP Table get cells($table; 1; 2; 2; 3) $range:=WP Text range($selected_cells; wk start text; wk end text) WP SET TEXT($range; "Name:"; wk replace) WP SET ATTRIBUTES($selected_cells; wk height; ".5in") |