PC SOFT

ONLINE HELP
FOR WINDEV, WEBDEV AND WINDEV MOBILE

Home | Sign in | English US
  • Handling a Table by programming
WINDEV
WindowsLinuxUniversal Windows 10 AppJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadApple WatchUniversal Windows 10 AppWindows Mobile
Others
Stored procedures
Inserts a table into a Word Processing document ir replaces the specified fragment with a new table.
Caution: This documentation presents the last features of the Word Processing control. Make sure that all the necessary modules are updated.
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
Versions 24 and later
docFragment variable with the inserted fragment.
New in version 24
docFragment variable with the inserted fragment.
docFragment variable with the inserted fragment.
<Document>: Document variable or character string (with or without quotes)
Document to use. This document corresponds to:
  • WINDEV the name of a Word Processing control.
  • a Document variable.
<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.
This syntax is available from version 220071.

Replacing the existing fragment by a new table Hide the details

<Result> = DocInsertTable(<Fragment> [, <Number of columns> [, <Number of rows>]])
<Result>: docFragment variable
Versions 24 and later
docFragment variable with the inserted fragment.
New in version 24
docFragment variable with the inserted fragment.
docFragment variable with the inserted fragment.
<Fragment>: docFragment variable
Name of docFragment variable corresponding to the fragment to use. The current fragment content will be replaced by 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 by programming

A table in a Word Processing document can be handled by the WLanguage functions for managing arrays.
Some examples:
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
nSubscript is int = Add(para..Table..Rows)
 
// Input in cell 2,2
para..Table..Cells[2,2]..Content..Text = "I'm 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..ParagraphIndex)
Example for creating a table in a document with the content of a Table control:
// A window contains a memory Table control 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 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 : wd240mdl.dll
Minimum required version
  • 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
Aug. 19 2019