KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Appending Text into a Cell in 4D Write Pro
PRODUCT: 4D Write Pro | VERSION: 20 | PLATFORM: Mac & Win
Published On: December 30, 2024

A developer may have tables in a 4D Write Pro document and may want to append text programmatically to text already in a cell. At the end of every cell there is a cell-terminating character in the form of a carriage return. So in order to append directly without the text being put into the next cell or on a new line, the range set must not include the carriage return. This can be done simply by modifying the end range with a -1 like the following (Given that $cell is a cell selected using WP Table get cells):

$range:=WP Text range($cell; wk start text; wk end text)
$range:=WP Text range($range; $range.start; $range.end-1)

The developer may now use $range as the first parameter in WP SET TEXT followed by the text they want to insert as the second parameter and wk append as the third parameter. Here is an example of this:

WP SET TEXT($range; "Text to append."; wk append)