I am using officer
R package to replace values in a Word
document. How to replace existing placeholder (here place
) by a multi line text of unknown length? I have tried \n
and <br>
for breakline without success.
library(officer)
my_doc <- read_docx()
my_doc <- officer::body_add_par(my_doc, "place")
my_doc <- body_replace_all_text(my_doc, "place", "first line \n<br> next_line")
output_file <- tempfile(fileext = ".docx")
output_file
print(my_doc, target = output_file)
A solution would be to split the character string in a vector. Put place_1
to place_max
in the word document and replace it with the right line from 1 to k and put empty strings in the remaining ones.
I am searching for a better solution. Thanks a lot for any clue.