Word Add text

Keeping on with our look at Word we need to able to add text to the documents we are creating.

001
002
003
004
005
006
007
008
009
010
011
function Add-Text {
    param (
        [string] $style = "Normal",
        [string] $text 
    )
    $global:paragraph = $doc.Content.Paragraphs.Add()
    $range = $paragraph.Range
    $Paragraph.Range.Text = $Text
    $Paragraph.Range.Style = $Style
    $Paragraph.Range.InsertParagraphAfter()
}

 

Add a paragraph then set the style and the paragraph text.  The text could come from a file using get-content. InsertParagraph() pushes the paragraph into the document.

Instead of setting the style we could explicitly set the font and its size.

Technorati Tags: ,,

Advertisements
This entry was posted in PowerShell V2. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s