Search code examples
rofficer

insert an external docx using "officer" pakage


Why doesn't work body_add_docx method in package "officer"? Where did I make mistake?

library(officer)
library(magrittr)

read_docx(path = "/home/user/page1.docx") %>% # load page1.docx as base document
  body_add_break() %>% # add page break
  body_add_docx(src="/home/user/page2.docx") %>% #FIXME: This method doesn't work
  print(target = "/home/user/out.docx") # out.docx conteins only page1.docx !?

Solution

  • Code below works only for Windows, MS Word and only without page break.

    For Linux, LibreOffice, google document it doesn't work.

    library(officer)
    library(magrittr)
    
    read_docx(path = "/home/user/page1.docx") %>%
      # body_add_break() %>% # with page break it doesn't work
      body_add_docx(src="/home/user/page2.docx") %>% # only for Widows and MS Word
      print(target = "/home/user/out.docx")