DescTools (version 0.99.11)

WrdText: Insert Normal Text to Word

Description

Write text in defined font and append a carriage return if requested.

Usage

WrdText(txt, fixedfont = TRUE, fontname = NULL, fontsize = NULL, 
        bold = FALSE, italic = FALSE, col = NULL,
        alignment = c("left","right","center"), spaceBefore=0, spaceAfter=0,
        lineSpacingRule = wdConst$wdLineSpaceSingle, 
        appendCR = TRUE, wrd = getOption("lastWord"))

Arguments

txt
the text to be inserted.
fixedfont
should a fixedfont be used. Default is TRUE.
fontname
the font of the text. If left to NULL the fixedfont will be used, and if the option does not exist it will be set to Consolas.
fontsize
the fontsize of the text. If left to NULL the fixedfontsize will be used, and if the option does not exist it will be set to 7.
bold
should the text be bold?
italic
should the text be italic?
col
the text color, defaults to black.
alignment
alignment of the paragraph, can be one out of left, right, center
spaceBefore
space before the paragraph in pts as set in Word.
spaceAfter
space after the paragraph in pts as set in Word.
lineSpacingRule
spacing in pts
appendCR
should a carriage return be appended to the text. Default is TRUE.
wrd
the pointer to a word instance. Can be a new one, created by GetNewWrd() or an existing one, created by GetCurrWrd(). Default is the last created pointer stored in getOption("lastWord").

Value

  • Returns a list of the attributes of the font in the current cursor position.
  • namethe fontname
  • sizethe fontsize
  • boldbold
  • italicitalic

See Also

WrdSetFont, WrdPlot, GetNewWrd, GetCurrWrd

Examples

Run this code
# Windows-specific example
# Let's write a story
data(d.diamonds)

# start word
wrd <- GetNewWrd()

WrdCaption("My Word-Story", stylename=wdConst$wdStyleHeading1)

WrdText("This will be the structure of d.diamonds:\n\n", appendCR=FALSE, 
        fontname="Arial", fontsize=10)
WrdText(capture.output(str(d.diamonds)))

wrd[["Selection"]]$InsertBreak(wdConst$wdPageBreak)
WrdText("Lets insert a table (and this ist written Times)!", fontname="Times", 
        fontsize=12, appendCR=FALSE, bold=T)

# insert table
wrd[["ActiveDocument"]][["Tables"]]$Add( wrd[["Selection"]][["Range"]], 
                                         NumRows=2, NumColumns=2 )
WrdText("First Cell", fontname="Arial", fontsize=10)
wrd[["Selection"]]$MoveRight( Unit=wdConst$wdCell, Count=1 )
WrdText("Second Cell")
wrd[["Selection"]]$MoveRight( Unit=wdConst$wdCell, Count=1 )

wrd[["Selection"]]$MoveRight( Unit=wdConst$wdCharacter, Count=2, 
                              Extend=wdConst$wdExtend )
wrd[["Selection"]][["Cells"]]$Merge()
WrdText("This cell was merged....", fontname="Arial", fontsize=10)


# exit the table range
wrd[["Selection"]]$EndOf( wdConst$wdTable )

wrd[["Selection"]]$MoveRight( wdConst$wdCharacter, 2, 0 )
wrd[["Selection"]]$TypeParagraph()

# let's insert a bookmark
wrd[["ActiveDocument"]][["Bookmarks"]]$Add("myBookmark")
wrd[["Selection"]]$MoveRight( Unit=wdConst$wdCharacter, Count=1 )
WrdText("\n\n", fontname="Arial", fontsize=10)

# set border for a paragraph
BorderBottom <- wrd[["Selection"]][["ParagraphFormat"]][["Borders"]]$Item(-3)
BorderBottom[["LineStyle"]] <- 1
wrd[["Selection"]]$MoveRight( wdConst$wdCharacter, 1, 0 )
WrdText("This paragraph has a Border", fontname="Arial", fontsize=10)
wrd[["Selection"]]$MoveRight( wdConst$wdCharacter, 2, 0 )
WrdText("\n\n", fontname="Arial", fontsize=10)

# insert new landscape section
wrd[["Selection"]]$InsertBreak(wdConst$wdSectionBreakNextPage)
wrd[["Selection"]][["PageSetup"]][["Orientation"]] <- wdConst$wdOrientLandscape

# new text
WrdText("Text in landscape", fontname="Impact", fontsize=20)
wrd[["Selection"]][["PageSetup"]][["Bottommargin"]] <- 4 * 72
wrd[["Selection"]][["PageSetup"]][["Leftmargin"]] <- 4 * 72
# wrd[["Selection"]][["PageSetup"]][["Topmargin"]] <- 4 * 72
# wrd[["Selection"]][["PageSetup"]][["Rightmargin"]] <- 4 * 72  

# return to the bookmark
wrd[["Selection"]]$GoTo( wdConst$wdGoToBookmark, 0, 0, "myBookmark") 

# and insert text
WrdText("Back again")

# goto end of document
wrd[["Selection"]]$EndKey(wdConst$wdStory)

Run the code above in your browser using DataCamp Workspace