Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

body_add_flextable

add flextable into a Word document


Description

add a flextable into a Word document.

Usage

body_add_flextable(
  x,
  value,
  align = "center",
  pos = "after",
  split = FALSE,
  topcaption = TRUE
)

body_replace_flextable_at_bkm(
  x,
  bookmark,
  value,
  align = "center",
  split = FALSE
)

Arguments

x

an rdocx object

value

flextable object

align

left, center (default) or right.

pos

where to add the flextable relative to the cursor, one of "after", "before", "on" (end of line).

split

set to TRUE if you want to activate Word option 'Allow row to break across pages'.

topcaption

if TRUE caption is added before the table, if FALSE, caption is added after the table.

bookmark

bookmark id

body_replace_flextable_at_bkm

Use this function if you want to replace a paragraph containing a bookmark with a flextable. As a side effect, the bookmark will be lost.

Examples

library(officer)

# autonum for caption
autonum <- run_autonum(seq_id = "tab", bkm = "mtcars")

ftab <- flextable( head( mtcars ) )
ftab <- set_caption(ftab, caption = "mtcars data", autonum = autonum)
ftab <- autofit(ftab)
doc <- read_docx()
doc <- body_add_flextable(doc, value = ftab)
fileout <- tempfile(fileext = ".docx")
# fileout <- "test.docx" # uncomment to write in your working directory
print(doc, target = fileout)

flextable

Functions for Tabular Reporting

v0.6.10
GPL-3
Authors
David Gohel [aut, cre], Clementine Jager [ctb], Quentin Fazilleau [ctb], Maxim Nazarov [ctb] (rmarkdown for docx output), Titouan Robert [ctb], Michael Barrowman [ctb] (inline footnotes), Atsushi Yasumoto [ctb] (support for bookdown cross reference), Paul Julian [ctb] (support for gam objects)
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.