Word Read Tables
Word Read Tables
Section titled “Word Read Tables”Type: word-read-tables · Package: Word Activities v1.0.4 · Output: List<DataTable>
Reads all the tables of a Word document and returns them as a list of DataTables (one per table in the document). Useful to extract tabular data from documents: a price list, a listing, an appendix.
How it works
Section titled “How it works”Finds the document’s tables, in order, and turns each one into a DataTable. It accepts session or path — see the two modes; with path it opens the file, reads it and closes it without changes.
- With
hasHeader = true(default): the first row gives the column names (trimmed of leading and trailing spaces) and the rest are data rows. - With
hasHeader = false: columns are namedCol1,Col2… and every row is data. - The number of columns is set by the first row. If a row has fewer cells (for example, because of merged cells), the missing ones stay empty; if it has more, the extra ones are ignored.
- All cells are read as text.
- Tables nested inside another table are also returned, as separate items in the list.
hasHeaderis set in the editor; it does not accept expressions.
Required parameters
Section titled “Required parameters”None — but you must provide session or path.
Optional parameters
Section titled “Optional parameters”| Parameter | Type | Default | Description |
|---|---|---|---|
session | ZoanWordSession | — | Session from Word Open (instead of path). Inherited automatically inside a body. |
path | string | — | Path to the .docx (quick mode). Only used when there is no session. |
hasHeader | bool | true | The first row of each table holds the headers. |
Output
Section titled “Output”Returns a List of DataTable, one per table in document order. If the document has no tables, the list is empty. Get one table with tables[0] or first(tables).
Example
Section titled “Example”Process the first table of the document:
Word Read Tables path = asset("appendix.docx") → output: tablesIf condition = count(tables) > 0 └─ then: Set Variable name = firstTable value = first(tables) Log message = "Rows: " + rowCount(firstTable)Common errors
Section titled “Common errors”| Message | Cause and fix |
|---|---|
'session' or 'path' is required. | There is no session and no path. |
File not found. | The path does not exist on the robot’s machine. |
| Duplicate column name error | With hasHeader = true, two cells in the first row have the same text. Use hasHeader = false and rename the columns afterwards with DataTable. |
Related activities
Section titled “Related activities”- Word Append Table — write a table into a document.
- DataTable — process the extracted tables.