ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

This content has been translated automatically.  Click here  to view the French version.
Help / WLanguage / WLanguage functions / Controls, pages and windows / Word Processing functions
  • Handling a Table programmatically
WINDEV
WindowsLinuxJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadIOS WidgetApple WatchMac Catalyst
Others
Stored procedures
Inserts a table into a Word Processing document ir replaces the specified fragment with a new table.
Example
// Insère un tableau à la position 1 de taille 3x3
DocInsertTable(TT_Tableau, 1, 3, 3)
// Insère un tableau à la position du curseur de taille 3 colonnes et 2 lignes
DocInsertTable(TT_Tableau, TT_Tableau.Curseur, 3, 2)
Syntax

Inserting a table into a Word Processing document Hide the details

<Result> = DocInsertTable(<Document> , <Position> [, <Number of columns> [, <Number of rows>]])
<Result>: docFragment variable
docFragment variable with the inserted fragment.
<Document>: Document or String variable
Document to use. This document corresponds to:
  • WINDEV the name of a Word Processing control.
  • a variable of type Document.
<Position>: Integer
Position where the table will be inserted. This position is expressed in number of characters.
<Number of columns>: Optional integer
Number of columns in the table. This parameters corresponds to 1 by default.
<Number of rows>: Optional integer
Number of rows in the table. This parameters corresponds to 1 by default.

Replacing the existing fragment by a new table Hide the details

<Result> = DocInsertTable(<Fragment> [, <Number of columns> [, <Number of rows>]])
<Result>: docFragment variable
docFragment variable with the inserted fragment.
<Fragment>: docFragment variable
Name of the docFragment variable that corresponds to the fragment to handle. The current fragment content will be replaced with the created table.
<Number of columns>: Optional integer
Number of columns in the table. This parameters corresponds to 1 by default.
<Number of rows>: Optional integer
Number of rows in the table. This parameters corresponds to 1 by default.
Remarks

Handling a Table programmatically

A table in a Word Processing document can be handled by the WLanguage functions for managing arrays.
For example:
Example:
// Insère un tableau à la position 1 de taille 3x3
DocInsertTable(TT_ExempleTT, 1, 3, 3)

// Définition d'un fragment correspondant au tableau
f is docFragment(TT_ExempleTT.Valeur, TT_ExempleTT.Curseur, 0)

let para <- f.Paragraph[1]
IF para.Table = Null THEN
	RETURN
END

doc is Document <- TT_ExempleTT.Valeur

// Ajoute une ligne au tableau
nIndice is int = Add(para.Table.Rows)

// Saisie dans la cellule 2,2
para.Table.Cells[2,2].Content.Text = "Je suis dans la cellule 2,2"

// Supprime la ligne 3
Delete(para.Table.Rows, 3)

// Supprime la colonne 3
Delete(para.Table.Columns, 3)

// Supprime le tableau entier où se trouve le curseur
Delete(doc.Paragraph, para.ParagraphIndex)
Example for creating a table in a document with the content of a Table control:
// Une fenêtre contient un champ Table par programmation nommé TABLE_Démo
// et un champ Traitement de texte nommé TT_Démo
// Le code suivant ajoute un tableau dans le champ Traitement de texte avec :
// - en première ligne du tableau, le titre des colonnes du champ Table,
// - le contenu du champ Table dans les lignes suivantes du tableau.

MonDoc is Document
cTable is Control <- TABLE_Démo
pCol is Control

FragmentDeb is docFragment(MonDoc,1)
FragmentDeb.Formatting.FontSize = 24
FragmentDeb.Formatting.TextColor = DarkRed
FragmentDeb.Text = "Tableau dans TTX avec " + cTable.Libellé + CR + CR

// Insertion du tableau dans le document en mémoire ...
DocInsertTable(MonDoc, 20, TableCount(cTable, toColumn), cTable.Occurrence + 1)

FOR EACH para OF MonDoc.Paragraph
	IF para.Tableau <> Null THEN
		// Pour toutes les colonnes du champ table ...
		FOR nColonne = 1 _TO_ TableCount(cTable, toColumn)

			// Première ligne du tableau contient le titre des colonnes
			pCol <- TableEnumColumn(cTable, nColonne)
			para.Tableau.Cellules[1, nColonne].Contenu.Texte = pCol.Libellé

			// Remplissage de toutes les lignes de cette colonne
			FOR nLigne = 1 _TO_ cTable.Occurrence
				para.Tableau.Cellules[nLigne+1, nColonne].Contenu.Texte = pCol[nLigne]
			END
		END
		BREAK
	END
END

// Document en mémoire affecté au champ Traitement de texte
TT_Démo = MonDoc
Component: wd300mdl.dll
Minimum version required
  • Version 22
This page is also available for…
Comments
using the DocInsertTable
1) you must add at least 2 lines in the docinserttable

DOC is document <- edt_doc // edt_doc is the document control

// inserts a document at position w 2 lines.
Frag is docFragment = DocInsertTable(doc,position,1,2)

now we look at the fragment for the lines we just added.. the table will usually NOT be in the first paragraph of the fragment so you must loop till you find it.

for each pTable of Frag..Paragraph
if pTable = Null then continue
for each string aString,tndx of arrString separated by CR
indx = add(ptable..table..Rows)
ptable..table..cells[indx,1)..content..text = aString
END
//remove the top 2 blank lines
delete(ptable..table..Rows,1)
delete(ptable..table..Rows,1)
//once 1st line deleted line 2 becomes line 1 so you delete again

Andy <<Cowboy>>Stapleton
andy@wxperts.com



Howard Stapleton
19 Aug. 2019

Last update: 03/25/2025

Send a report | Local help