Word Add a table

There seems to be two types of paragraph I create in Word documents – text or tables.  Lets start by adding a table.

001
002
003
004
005
006
007
008
009
function Add-Table {
    param (
        [int] $row = 2,
        [int] $col = 5
    )
    $global:paragraph = $doc.Content.Paragraphs.Add()
    $range = $paragraph.Range
    $global:table = $doc.Tables.Add($range,$row,$col)
}

 

The function Add-Table takes two integers as parameters. They define the rows and columns of the table.  The way that seems to work best is to add a paragraph to contain the table and then add the table into the paragraph.  If we just add the table to the document it overwrites the contents of the document with the table. oops.

Notice that I’m using global variables again so that they can be used across the environment.

Next time we will add some data to the table.

Technorati Tags: ,,,
Published Mon, Aug 31 2009 13:22 by RichardSiddaway
Filed under:

Leave a Comment

(required) 
(required) 
(optional)
(required) 
If you can't read this number refresh your screen
Enter the numbers above: