I am trying to use the officer
package in R to create multiple outputs with columns and then combine the outputs into a single document.
I am able to create the initial outputs with columns, but when I combine them with body_add_docx()
the column formatting goes away.
Wondering if I am missing something with my implementation.
# sample text
str1 <- "Lorem ipsum dolor sit amet, consectetur adipiscing elit."
str1 <- rep(str1, 20)
str1 <- paste(str1, collapse = " ")
# Create initial section with columns
x <- read_docx()
x <- body_add_par(x, str1, style = "Normal") %>%
body_end_section_columns(widths = c(3, 3), space = 0, sep = FALSE)
print(x, target = "tmp1.docx")
# Create another output with columns
x <- read_docx()
x <- body_add_par(x, str1, style = "Normal") %>%
body_end_section_columns(widths = c(3, 3), space = 0, sep = FALSE)
print(x, target = "tmp2.docx")
# Combine the rendered sections together
read_docx(path = "tmp1.docx") %>%
body_add_break() %>%
body_add_docx(src = "tmp2.docx") %>%
print(target = "final.docx")
The final output does not have the same column structure as the inputs.