
Manipulate Microsoft Word, PowerPoint and Excel Documents with 'officer'
Source:R/officer.R
officer.RdThe officer package facilitates access to and manipulation of 'Microsoft Word', 'Microsoft PowerPoint' and 'Microsoft Excel' documents from R. It also supports the writing of 'RTF' documents.
Examples of usage are:
Create Word documents with tables, titles, TOC and graphics
Importation of Word and PowerPoint files into data objects
Write updated content back to a PowerPoint presentation
Clinical reporting automation
Production of reports from a shiny application
To start with officer, read about read_docx(), read_pptx(),
read_xlsx() or rtf_doc().
The package also provides several objects that can be printed
in 'R Markdown' documents for advanced Word or PowerPoint
reporting as run_autonum() and block_caption().
Word documents
Start with read_docx() and save with print.rdocx().
Content is added with one function per kind of content, such as
body_add_par(), body_add_fpar(), body_add_table(), body_add_gg()
and body_add_toc(). They add it at the cursor, which is moved with
cursor_begin(), cursor_reach() and similar functions. For large documents,
see body_append_start_context().
Sections are defined with block_section() and body_end_block_section().
Use docx_summary() to read the content of an existing document as a
data.frame.
PowerPoint presentations
Start with read_pptx() and save with print.rpptx(). Add slides with
add_slide(), then content with ph_with(). layout_summary() and
plot_layout_properties() show what a template provides.
A new slide contains no shapes, and each call to ph_with() creates a new
one. Despite the ph_ prefix, which stands for placeholder, it does not fill
an existing placeholder or replace what is already there. See section
How it works of ph_with().
Use pptx_summary() to read the content of an existing presentation as a
data.frame.
Excel workbooks
Start with read_xlsx() and save with print.rxlsx(). Add sheets with
add_sheet(), then content with sheet_write_data() and
sheet_add_drawing().
RTF documents
Start with rtf_doc() and save with print.rtf(). Add content with
rtf_add(). There is no cursor: elements can only be added one after the
other, at the end of the document, and an existing RTF file cannot be read.
Formatted content
These objects work with several formats: fpar() and ftext() for formatted
text, fp_text() and fp_par() for their properties, block_list() for a
sequence of blocks.
Copy an officer object
'officer' objects of class rdocx or rpptx use R6 classes with reference
semantics. Assignment does NOT create a copy:
If you need independent documents (e.g., in loops), read the template each time:
See also
The user documentation: https://ardata-fr.github.io/officeverse/ and manuals https://davidgohel.github.io/officer/
Author
Maintainer: David Gohel david.gohel@ardata.fr
Authors:
David Gohel david.gohel@ardata.fr
Stefan Moog moogs@gmx.de
Mark Heckmann heckmann.mark@gmail.com (ORCID)
Other contributors:
ArData [copyright holder]
Frank Hangler frank@plotandscatter.com (function body_replace_all_text) [contributor]
Liz Sander lsander@civisanalytics.com (several documentation fixes) [contributor]
Anton Victorson anton@victorson.se (fixes xml structures) [contributor]
Jon Calder jonmcalder@gmail.com (update vignettes) [contributor]
John Harrold john.m.harrold@gmail.com (function annotate_base) [contributor]
John Muschelli muschellij2@gmail.com (google doc compatibility) [contributor]
Bill Denney wdenney@humanpredictions.com (ORCID) (function as.matrix.rpptx) [contributor]
Nikolai Beck beck.nikolai@gmail.com (set speaker notes for .pptx documents) [contributor]
Greg Leleu gregoire.leleu@gmail.com (fields functionality in ppt) [contributor]
Majid Eismann [contributor]
Wahiduzzaman Khan (vectorization of remove_slide) [contributor]
Hongyuan Jia hongyuanjia@cqust.edu.cn (ORCID) [contributor]
Michael Stackhouse mike.stackhouse@atorusresearch.com [contributor]