[Top]  [Chapter]  [Previous]  [Next]

Tables in TextDynamic are represented by nested paragraphs. The table, table row and cell are paragraph objects which are children of each other. cells in the same rows are siblings to each other, as are rows.


The structure is so just as it is known from HTML:







TextDynamic supports 4 different ways to create a table by code. We offer so many possibilities because the data which has to be placed into the table cells can come in different ways and order. In general we favourize the use of a callback to fill the cell text, but it is not always possible to callbacks. The possibility to select from different methods makes it easy to adapt existing logic to work with TextDynamic.


Method 1 - use callback:

Call TextCursor.AddTable and use the event OnCreateNewCell to format and fill the cell. If you do not know the count of rows in advance pass 100000 and abort the creation loop inside the OnCreateNewCell event using the variable parameter "AbortAtRowEnd".


Tip: Alternatively to the callback you can use the method ASetCellProp to modify a group of cells after the complete table was created.


Advantage: Table is created automatically, only cells which need modification need 'attention'.

Disadvantage: Callback function can be difficult to read and maintain. Sometimes callback is not possible (script languages)


Method 2 - simulate user input:

Call TextCursor.AddTable - then use the properties CPTableRowNr, CPTableColNr to "move around" and insert text using InputString. You can also move the cursor using CPMoveNextRow, CPMoveNextCell which would be faster.


Advantage: Table is created automatically, only cells which need modification need 'attention'.

Disadvantage: can be slow with large tables


Method 3 - create from top to bottom:

Use TextCursor.InputTable, then InputRowStart, as many InputCell ass needed and InputRowEnd to close the current row. Create new row with InputRowStart and so on.


Advantage: fast, easy to understand logic

Disadvantage: can create rows with uneven count of columns


Method 4 - work with objects:

Create a new paragraph or modify Memo.CurrPar to make it a table object: par.SetParType((int)ParagraphType.Table). Now you can use AppendChild to create a new row and for each row use AppendChild to create a new cell. To process a different paragraph you can either use the Select methods, or you save the paragraph ID and use par.SetPtr(id).


Please see the example code in topic IWPDataBlock.AppendParagraph.


Advantage: Table can be created without change of cursor position

Disadvantage: Difficult to understand, can create rows with uneven count of columns. Exceptions are possible when SetPtr() is not correctly used.

[tables.htm]    Copyright © 2007 by WPCubed GmbH