Categories

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: ,,

Leave a Reply