Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/davidgohel/flextable/llms.txt

Use this file to discover all available pages before exploring further.

save_as_docx() writes one or more flextable objects to a Word file. This is a convenience function that wraps the officer package. For more control over document structure, use the officer API directly.

Function signature

save_as_docx(..., values = NULL, path, pr_section = NULL, align = "center")

Parameters

...
flextable
required
One or more flextable objects, optionally named. Named objects use the name as a paragraph title before the table.
values
list
A list of flextable objects (optionally named). If supplied, ... is ignored.
path
string
required
Path to the .docx file to create.
pr_section
prop_section
An officer::prop_section object defining page layout properties such as orientation, page size, and margins.
align
string
default:"center"
Horizontal alignment of the table on the page: "left", "center", or "right".

Return value

A string containing the full path of the generated file.

Examples

Save a single table:
library(officer)
ft <- flextable(head(iris))
tf <- tempfile(fileext = ".docx")
save_as_docx(ft, path = tf)
Save multiple named tables with a landscape page layout:
library(officer)
ft1 <- flextable(head(iris))
ft2 <- flextable(head(mtcars))

sect_properties <- prop_section(
  page_size = page_size(orient = "landscape", width = 8.3, height = 11.7),
  type = "continuous",
  page_margins = page_mar()
)

tf <- tempfile(fileext = ".docx")
save_as_docx(
  `iris table`   = ft1,
  `mtcars table` = ft2,
  path           = tf,
  pr_section     = sect_properties
)

See also

Build docs developers (and LLMs) love