0

I want to generate a word document from a pre saved word template, I have added placeholders on word template, but I'm not able to save the texts on placeholder location. I tried using ph_with function but it gives error as its for .pptx, please tell me which function to use for saving the desired text to a specific placeholder location. Also I'm adding the placeholders in word template by typing (Placeholder1 ...and so on) is this correct method?

template <- system.file(package = "officer", "doc_examples", "protocol_template.docx")                            
    doc <- read_docx(path = template)
    ph_with(doc, 
            value = input$text, 
            location = ph_location_label(ph_label = "Placeholder1"))
ricoderks
  • 1,619
  • 9
  • 13
Surya
  • 3
  • 2

1 Answers1

0

After loading a word document you can use the body_replace_all_text function to pipe in the desired text into the document.

body_replace_all_text(
  x,
  old_value,
  new_value,
  only_at_cursor = FALSE,
  warn = TRUE,
  ...
)
matthanc
  • 11
  • 1