Table Support Category

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

In TextDynamic tables are handled the same as HTML table. On table object contains table rows which contain table cell objects. In TextDynamic all this objects internally are paragraph objects, only the property ParagraphType selects a different mode. This makes it possible to replace an empty paragraph with a table by simply changing its mode and adding row and cell children to it.


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.











Methods to quickly modify an existing table without user interaction:









Also available:


TextCommand(13) combines all adjacent tables. Returns the count of deleted tables.


TextCommand(14) tries to create merged cells for cells which are wider than the others in a column. Returns the count of changed tables.



[idh_cat_tables.htm]    Copyright © 2007 by WPCubed GmbH