ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

Help / WLanguage / WLanguage functions / Controls, pages and windows / Word Processing functions
  • Handling a Table through programming
WINDEV
WindowsLinuxUniversal Windows 10 AppJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadIOS WidgetApple WatchMac CatalystUniversal Windows 10 App
Others
Stored procedures
Inserts a table into a Word Processing document ir replaces the specified fragment with a new table.
Example
// Inserts a 3x3 table at position 1
DocInsertTable(WP_Table, 1, 3, 3)
// Inserts a table containing 3 columns and 2 rows at cursor position
DocInsertTable(WP_Table, WP_Table.Cursor, 3, 2)
Syntax

Inserting a table into a 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 variable or character string
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 through programming

A table in a Word Processing document can be handled by the WLanguage functions for managing arrays.
For example:
Example:
// Inserts a 3x3 table at position 1
DocInsertTable(WP_ExampleWP, 1, 3, 3)
 
// Define a fragment corresponding to the table
f is docFragment(WP_ExampleWP.Value, WP_ExampleWP.Cursor, 0)
 
let para <- f.Paragraph[1]
IF para.Table = Null THEN
RETURN
END
 
doc is Document <- WP_ExampleWP.Value
 
// Adds a row to the table
nIndex is int = Add(para.Table.Rows)
 
// Input in cell 2,2
para.Table.Cells[2,2].Content.Text = "I am in cell 2,2"
 
// Deletes row 3
Delete(para.Table.Rows, 3)
 
// Deletes column 3
Delete(para.Table.Columns, 3)
 
// Deletes the entire table where the cursor is positioned
Delete(doc.Paragraph, para.ParagraphSubscript)
Example for creating a table in a document with the content of a Table control:
// A window contains a Table control populated programmatically named TABLE_Demo
// and a Word Processing control named WP_Demo
// The following code adds a table into the Word Processing control with:
// - in first table row, the title of columns found in the Table control,
// - the content of Table control in the other table rows.
 
MyDoc is Document
cTable is Control <- TABLE_Demo
pCol is Control
 
FragmentStart is docFragment(MyDoc,1)
FragmentStart.Formatting.FontSize = 24
FragmentStart.Formatting.TextColor = DarkRed
FragmentStart.Text = "Table in WP with " + cTable.Caption + CR + CR
 
// Insert the table into the document in memory ...
DocInsertTable(MyDoc, 20, TableCount(cTable, toColumn), cTable.Occurrence + 1)
 
FOR EACH para OF MyDoc.Paragraph
IF para.Table <> Null THEN
// For all columns of the table control ...
FOR nColumn = 1 _TO_ TableCount(cTable, toColumn)
 
// First tab le line containing the title of columns
pCol <- TableEnumColumn(cTable, nColumn)
para.Table.Cells[1, nColumn].Content.Text = pCol.Caption
 
// Fill all rows of this column
FOR nRow = 1 _TO_ cTable.Occurrence
para.Table.Cells[nRow+1, nColumn].Content.Text = pCol[nRow]
END
END
BREAK
END
END
 
// Document in memory assigned to the Word Processing control
WP_Demo = MyDoc
Component: wd290mdl.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: 04/06/2023

Send a report | Local help