update_toc: Update the tables of contents of a .docx file created with...

View source: R/functions.R

update_tocR Documentation

Update the tables of contents of a .docx file created with the 'officer' package

Description

This function exports the document as a temporary .docx file, creates a temporary .vbs file to update all references of all tables of contents and save, runs the .vbs file in command prompt, overrides x using the 'read_docx()' function of the 'officer' package, deletes the temporary files, and returns the updated .docx file.

Usage

update_toc(x)

Arguments

x

document created using 'read_docx()' function from 'officer' package

Examples

doc <- read_docx()
doc <- body_add_par(doc, value = "Table of content", style = "heading 1")
doc <- body_add_toc(doc, level = 2)
doc <- body_end_section_continuous(doc)
doc <- body_add_par(doc, value = "Section 1", style = "heading 1")
doc <- body_add_par(doc, value = "This is a test.", style = "heading 2")
doc <- body_add_par(doc, value = "Section 1", style = "heading 1")
doc <- update_toc(doc)

joshmire/officerWinTools documentation built on July 5, 2023, 4:27 a.m.