change_styles

0th

Percentile

Replace Styles in a Word Document

Replace styles with others in a Word document. This function can be used for paragraph, run/character and table styles.

Usage
change_styles(x, mapstyles)
Arguments
x

an rdocx object

mapstyles

a named list, names are the replacement style, content (as a character vector) are the styles to be replaced. Use styles_info() to display available styles.

Aliases
  • change_styles
Examples
# NOT RUN {
library(magrittr)

mapstyles <- list(
  "centered" = c("Normal", "heading 2"),
  "strong" = "Default Paragraph Font"
)
doc <- read_docx() %>%
  body_add_par("A title", style = "heading 1") %>%
  body_add_par("Hello ", style = "Normal") %>%
  slip_in_text("world", style = "Default Paragraph Font") %>%
  slip_in_text("Message is: ", style = "Default Paragraph Font", pos = "before") %>%
  slip_in_text(" with a link",
    style = "strong",
    pos = "after", hyperlink = "https://davidgohel.github.io/officer/"
  ) %>%
  body_add_par("Another title", style = "heading 2") %>%
  body_add_par("Hello world!", style = "Normal") %>%
  change_styles(mapstyles = mapstyles)

print(doc, target = tempfile(fileext = ".docx"))
# }
Documentation reproduced from package officer, version 0.3.14, License: GPL-3

Community examples

Looks like there are no examples yet.