Reputation: 151
I followed the steps in this answer to combine two documents Writing word documents with the officer package: How to combine several rdocx objects?
But one document is a frontpage and the other document has headers. The problem is that when I join them, the front page also has headers.
How can I join or merge two documents while keeping separated the header from the frontpage?
#creating the front page.
#summarized version since it will have added features
my_doc_frontpage <- read_docx()
my_doc_frontpage <- my_doc_frontpage %>%
body_add_img(src = "logo.png", width = 1, height = 0.8, style = "centered")
print(my_doc_frontpage,"frontpage.docx")
#reading the file containing some headers.
#summarized version since it will have added features
my_doc <- read_docx("base.docx")
my_doc <- body_add_docx(my_doc,"frontpage.docx")
print(my_doc,"combined.docx")
but the combined.docx file has the frontpage with the header modified
Upvotes: 1
Views: 1162
Reputation: 151
So, after some time I found a way to solve this.
my_doc <- read_docx("template.docx") my_doc <- my_doc %>% headers_replace_all_text("front1"," ") #blank since it's frontpage my_doc <- my_doc %>% headers_replace_all_text("page1","Document") #new header
And that's it
Upvotes: 2