body_import_docx | R Documentation |
Import body content and footnotes of a Word document into an rdocx object.
The function is similar to body_add_docx()
but instead of adding
the content as an external object, the document is read and all its
content is appended to the target document.
body_import_docx(
x,
src,
par_style_mapping = list(),
run_style_mapping = list(),
tbl_style_mapping = list(),
prepend_chunks_on_styles = list()
)
x |
an rdocx object |
src |
path to docx file to import |
par_style_mapping , run_style_mapping , tbl_style_mapping |
Named lists describing how to remap styles from the source document (
Examples: par_style_mapping = list( "Normal" = c("List Paragraph", "Body Text"), "heading 1" = "Heading 1" ) run_style_mapping = list( "Emphasis" = c("Emphasis", "Italic") ) tbl_style_mapping = list( "Normal Table" = c("Light Shading") ) Use |
prepend_chunks_on_styles |
A named list of run chunks to prepend
to runs with specific styles. The names of the list are paragraph style names
and the values run chunks to prepend. The first motivation for this argument
is to allow prepending of runs in paragraphs with a defined style, for example
to add a |
The following operations are performed when importing a document:
Numbering are copied from the source document to the target document.
Styles are not copied. If styles in the source document do not exist
in the target document, the style specified in the par_style_mapping
,
run_style_mapping
and tbl_style_mapping
arguments will be used instead.
If no mapping is provided, the default style will be used and a warning is emitted.
Other functions for adding content:
body_add_blocks()
,
body_add_break()
,
body_add_caption()
,
body_add_docx()
,
body_add_fpar()
,
body_add_gg()
,
body_add_img()
,
body_add_par()
,
body_add_plot()
,
body_add_table()
,
body_add_toc()
,
body_append_start_context()
library(officer)
# example file from the package
file_input <- system.file(
package = "officer",
"doc_examples/example.docx"
)
# create a new rdocx document
x <- read_docx()
# import content from file_input
x <- body_import_docx(
x = x,
src = file_input,
# style mapping for paragraphs and tables
par_style_mapping = list(
"Normal" = c("List Paragraph")
),
tbl_style_mapping = list(
"Normal Table" = "Light Shading"
)
)
# Create temporary file
tf <- tempfile(fileext = ".docx")
# write to file
print(x, target = tf)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.