I’m creating reports in Quarto rendering to MS Word (report.docx) and have a reference document (ref_doc.docx) which provides heading styles, the header, and page numbers.
The header of the reference document contains the following field code: { DOCPROPERTY "report_name" * MERGEFORMAT }
, along with some constant text.
In my quarto script I define report_name
which I need to appear in the header.
All I’ve managed to do so far is apply the correct report_name
value to the reference document, but this still requires going into the word document, right clicking and clicking ‘update field’ (I might as well then change all names manually!).
This is the relevant code so far:
report_name <- "My Example Report"
doc <- officer::read_docx("reference_document.docx")
doc <- officer::set_doc_properties(doc, report_name = report_name)
print(doc, target = "reference_document2.docx")
doconv::docx_update(input = "report.docx")
So there are two problems:
- I need the field to update without having to go into the document
- I need the reference document to change and then apply the change to the rendering script – I need this to all happen from rendering the one script.