Tech Tip: Utility Method to Insert Table Row Title on Each Page in Write Pro
PRODUCT: 4D Write Pro | VERSION: 19 | PLATFORM: Mac & Win
Published On: November 29, 2021
This is a utility method that inserts a row title in the beginning of a table and also in the beginning of each new page the specified table spans across in the write pro document. The method accepts a table reference and a collection of title names to set for each column. Other attributes of the inserted title row can be set by adding it into the utility method. If a title row already exists at the begining of the table, you can remove "| ($I=1)" on the 15th line in the utility method.
Before:
After:
Utility Method:
//========================================= //METHOD: WP_setTableRowHeader //DESCRIPTION: Insert table row for title in beginning of table and in the beginning of each new page the table spans across in write pro document //PARAMETERS: // $1 (Object): Table element to insert title row in // $2 (Collection): Column titles to set //========================================= C_OBJECT($1;$table_o;$rowPosition_o;$headerRow_o;$cell_o) C_COLLECTION($2;$headerVal_c;$rows_c) C_LONGINT($page;$i;$column) $table_o:=$1 $headerVal_c:=$2 $rows_c:=WP Get elements($table_o;wk type table row) $rowPosition_o:=WP Get position($rows_c[0]) $page:=$rowPosition_o.page $i:=1 While ($i<$rows_c.length) $pos:=$i For ($i;$pos;$rows_c.length) $rowPosition_o:=WP Get position($rows_c[$i-1]) If ($rowPosition_o.page>$page) | ($i=1) //remove "| ($i=1)" to skip first row //insert title row $headerRow_o:=WP Table insert rows($table_o;$i;1) //make sure inserted row did not go on previous page. Insert break if so If (WP Get position($headerRow_o).page<$rowPosition_o.page) WP INSERT BREAK($headerRow_o;wk page break;wk prepend) End if // Set attributes of inserted title row here.. // ex). WP SET ATTRIBUTES($headerRow;wk background color;"cyan") // Set attributes of inserted title row here.. //set cloumn title in row For ($column;1;$table_o.columnCount) $cell_o:=WP Table get cells($table_o;$column;$i) WP SET TEXT($cell_o;$headerVal_c[$column-1];wk prepend) End for $rows_c:=WP Get elements($table_o;wk type table row) $page:=$rowPosition_o.page End if End for End while |
Example of calling the utility method:
C_OBJECT(WParea;$table;$tableRange) C_COLLECTION($rows;$tables) $tableRange:=WP Table range(WParea) $tables:=WP Get elements($tableRange;wk type table) For each($table;$tables) WP_setTableRowHeader($table;New collection("Price";"Quantity")) End for each |