Tomas Weguelin
Tomas Weguelin

Reputation: 11

Can i change the formatting of specific words In my docx file with officer package in R?

I'm trying to change some specific words formatting to bold but can't find the the way to do it.

For example:

I would like to change the word "text" to bold in this code:

doc <- read_docx() %>%
   body_add_par("This is a sample text", style = "centered")

How could I do it?

Upvotes: 1

Views: 592

Answers (1)

Sven
Sven

Reputation: 1253

You can use body_add_fpar to achieve that. From the documentation:

bold_face <- shortcuts$fp_bold(font.size = 30)
bold_redface <- update(bold_face, color = "red")
fpar_ <- fpar(ftext("Hello ", prop = bold_face),
              ftext("World", prop = bold_redface ),
              ftext(", how are you?", prop = bold_face ) )
doc <- read_docx() %>% body_add_fpar(fpar_)

Upvotes: 1

Related Questions