Function Reference


_Word_DocTableRead

Reads a Word table and returns the content as a two-dimensional array

#include <Word.au3>
_Word_DocTableRead ( $oDoc, $vTable [, $iIndexBase = Default [, $sDelimiter = Default]] )

Parameters

$oDoc Word document object
$vTable Table object or index of the table in the table collection
$iIndexBase [optional] Can be 0 or 1 and specifies if the array starts with row 0 or 1 (default = 1)
$sDelimiter [optional] Specifies the character used to separate text into cells (default = @TAB)

Return Value

Success: Two-dimensional array with the content of the Word table.
Failure: "" and sets the @error flag to non-zero.
@error: 1 - $oDoc is not an object
2 - Error occurred when accessing the specified table index in the table collection. @extended is set to the COM error code
3 - Error occurred when accessing the specified table. @extended is set to the COM error code
4 - Error occurred when converting the text to a table. @extended is set to the COM error code

Remarks

Nested tables are ignored.
If $iIndexBase is set to 1 then row 0 of the array contains the row and column count.

Related

_Word_DocTableWrite

Example

#include <Array.au3>
#include <MsgBoxConstants.au3>
#include <Word.au3>

; Create application object
Local $oWord = _Word_Create()
If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocTableRead Example", _
        "Error creating a new Word application object." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
; Open the test document
Local $oDoc = _Word_DocOpen($oWord, @ScriptDir & "\Extras\Test.doc", Default, Default, True)
If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocTableRead Example", _
        "Error opening '.\Extras\Test.doc'." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
; Create a table from an array
Local $asArray[3][3] = [[1, 2, 3], ["a", "b", "c"], ["x", "y", "z"]]
Local $oRange = _Word_DocRangeSet($oDoc, -2)
Local $oTable = _Word_DocTableWrite($oRange, $asArray, 0)
If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocTableRead Example", _
        "Error creating the table." & @CRLF & "@error = " & @error & ", @extended = " & @extended)

; Read the first table in the document and return the content
Local $asResult = _Word_DocTableRead($oDoc, 1, 1)
If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocTableRead Example", _
        "Error reading the table to an array." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
_ArrayDisplay($asResult, "Word UDF: _Word_DocTableRead Example")