Title: | Export Data Frames to Excel Workbook |
---|---|
Description: | Collection of functions that allow to export data frames to excel workbook. |
Authors: | Damien Dotta [aut, cre], Julien Blasco [aut] |
Maintainer: | Damien Dotta <[email protected]> |
License: | MIT + file LICENSE |
Version: | 1.1.0 |
Built: | 2025-02-13 05:13:41 UTC |
Source: | https://github.com/ddotta/tablexlsx |
Function that adds a data frame to an (existing) .xlsx workbook sheet
add_table( Table, WbTitle, SheetTitle, TableTitle, StartRow = 1, StartCol = 1, FormatList = setNames(rep(list(Theme[["character"]]), length(colnames(Table))), colnames(Table)), Theme = xls_theme_default(), HeightTableTitle = 2, TableFootnote1 = "", TableFootnote2 = "", TableFootnote3 = "", MergeCol = character(0), ByGroup = character(0), GroupName = FALSE, asTable = FALSE )
add_table( Table, WbTitle, SheetTitle, TableTitle, StartRow = 1, StartCol = 1, FormatList = setNames(rep(list(Theme[["character"]]), length(colnames(Table))), colnames(Table)), Theme = xls_theme_default(), HeightTableTitle = 2, TableFootnote1 = "", TableFootnote2 = "", TableFootnote3 = "", MergeCol = character(0), ByGroup = character(0), GroupName = FALSE, asTable = FALSE )
Table |
: data frame to be exported to the workbook sheet |
WbTitle |
: workbook |
SheetTitle |
: string used for the sheet's name |
TableTitle |
: string used for the data frame's title |
StartRow |
: export start line number in the sheet (by default 1) |
StartCol |
: export start column number in the sheet (by default 1) |
FormatList |
: list that indicates the format of each column of the data frame |
Theme |
: styling theme, a named list of 'openxlsx' Styles |
HeightTableTitle |
: multiplier (if needed) for the height of the title line (by default 2) |
TableFootnote1 |
: string for TableFootnote1 |
TableFootnote2 |
: string for TableFootnote2 |
TableFootnote3 |
: string for TableFootnote3 |
MergeCol |
: character vector that indicates the columns for which to merge the modalities |
ByGroup |
character vector indicating the name of the columns by which to group |
GroupName |
boolean indicating whether the name of the grouping variable should be written |
asTable |
logical indicating if data should be written as an Excel Table (FALSE by default) |
excel wb object
An R list that contains the styles of each element for formatting data frames in excel files
style
style
A list of several items
Style for title
Style for footnote1
Style for footnote2
Style for footnote3
Style for col_header
Style for columns in character format
Style for columns in number format
Style for columns in character format with decimals
Style for columns in percent format
This function allows you to write R data frames given
in the 'object' argument to excel files located in the 'path' directory.
The function takes several arguments but the only two required are 'object' and 'path'.
See examples gallery : <https://ddotta.github.io/tablexlsx/articles/aa-examples.html>
toxlsx( object, path, tosheet = list(), title = list(), columnstyle = list(default = NULL), theme = xls_theme_default(), footnote1 = list(), footnote2 = list(), footnote3 = list(), mergecol = NULL, bygroup = list(), groupname = FALSE, filename = "Export", asTable = FALSE, automaticopen = FALSE )
toxlsx( object, path, tosheet = list(), title = list(), columnstyle = list(default = NULL), theme = xls_theme_default(), footnote1 = list(), footnote2 = list(), footnote3 = list(), mergecol = NULL, bygroup = list(), groupname = FALSE, filename = "Export", asTable = FALSE, automaticopen = FALSE )
object |
data.frame to be converted to excel |
path |
path to save excel file (either a directory name or a file name with full path) |
tosheet |
list of sheet names for each element of object. If omitted, sheets are named by default "Sheet 1", "Sheet 2"... |
title |
list of title for each element of object If omitted, title takes the name of the dataframe in 'object' |
columnstyle |
list of style for columns of each element of object Only useful if you want to customise the style of each column ' |
theme |
styling theme, a named list of 'openxlsx' Styles |
footnote1 |
list of footnote1 for each element of object If omitted, no footnote1 |
footnote2 |
list of footnote2 for each element of object If omitted, no footnote2 |
footnote3 |
list of footnote3 for each element of object If omitted, no footnote3 |
mergecol |
list of character vectors that indicate the columns for which we want to merge the modalities |
bygroup |
list of character vectors indicating the names of the columns by which to group |
groupname |
list of booleans indicating whether the names of the grouping variables should be written |
filename |
name for the excel file ("Export" by default). Ignored if 'path' is a file name. |
asTable |
logical indicating if data should be written as an Excel Table (FALSE by default) |
automaticopen |
logical indicating if excel file should open automatically (FALSE by default) |
an excel file
# Simply export a data frame to an xlsx file # For more examples, see examples gallery : # https://ddotta.github.io/tablexlsx/articles/aa-examples.html ## Not run: toxlsx(object = iris, path = tempdir()) ## End(Not run)
# Simply export a data frame to an xlsx file # For more examples, see examples gallery : # https://ddotta.github.io/tablexlsx/articles/aa-examples.html ## Not run: toxlsx(object = iris, path = tempdir()) ## End(Not run)
This function creates an xls theme for styling exported tables. All its arguments must be 'openxlsx' Style objects.
xls_theme( title, col_header, character, footnote1, footnote2, footnote3, mergedcell, ... )
xls_theme( title, col_header, character, footnote1, footnote2, footnote3, mergedcell, ... )
title |
Style for the title |
col_header |
Style for the columns header |
character |
Default style for data cells |
footnote1 |
Style for footnote1 |
footnote2 |
Style for footnote2 |
footnote3 |
Style for footnote3 |
mergedcell |
Style for merged cells |
... |
Other (named) custom styles |
a named list of class xls_theme, whose elements are 'openxlsx' Style objects.
xls_theme_plain()
,
xls_theme_default()
my_theme <- xls_theme( title = openxlsx::createStyle(), col_header = openxlsx::createStyle(), character = openxlsx::createStyle(), footnote1 = openxlsx::createStyle(), footnote2 = openxlsx::createStyle(), footnote3 = openxlsx::createStyle(), mergedcell = openxlsx::createStyle() ) ## Not run: toxlsx(object = iris, path = tempdir(), theme = my_theme) ## End(Not run)
my_theme <- xls_theme( title = openxlsx::createStyle(), col_header = openxlsx::createStyle(), character = openxlsx::createStyle(), footnote1 = openxlsx::createStyle(), footnote2 = openxlsx::createStyle(), footnote3 = openxlsx::createStyle(), mergedcell = openxlsx::createStyle() ) ## Not run: toxlsx(object = iris, path = tempdir(), theme = my_theme) ## End(Not run)
This function is a wrapper around [xls_theme()] that creates an xls theme for styling exported tables. It defines a theme whith sensible default formatting values. It also defines custom styles for "number", "decimal" and "percent column types. All its arguments must be 'openxlsx' Style objects.
xls_theme_default( title = openxlsx::createStyle(fontSize = 16, textDecoration = "bold"), footnote1 = openxlsx::createStyle(fontSize = 12), footnote2 = openxlsx::createStyle(fontSize = 12), footnote3 = openxlsx::createStyle(fontSize = 12), col_header = openxlsx::createStyle(fontSize = 12, textDecoration = "bold", border = c("top", "bottom", "left", "right"), borderStyle = "thin", wrapText = TRUE, halign = "center"), character = openxlsx::createStyle(fontSize = 12, border = c("top", "bottom", "left", "right"), borderStyle = "thin"), number = openxlsx::createStyle(fontSize = 12, numFmt = "### ### ### ##0", border = c("top", "bottom", "left", "right"), borderStyle = "thin"), decimal = openxlsx::createStyle(fontSize = 12, numFmt = "### ### ### ##0.0", border = c("top", "bottom", "left", "right"), borderStyle = "thin"), percent = openxlsx::createStyle(fontSize = 12, numFmt = "#0.0", border = c("top", "bottom", "left", "right"), borderStyle = "thin", halign = "center"), mergedcell = openxlsx::createStyle(fontSize = 12, border = c("top", "bottom", "left", "right"), borderStyle = "thin", wrapText = TRUE, valign = "center", halign = "center"), ... )
xls_theme_default( title = openxlsx::createStyle(fontSize = 16, textDecoration = "bold"), footnote1 = openxlsx::createStyle(fontSize = 12), footnote2 = openxlsx::createStyle(fontSize = 12), footnote3 = openxlsx::createStyle(fontSize = 12), col_header = openxlsx::createStyle(fontSize = 12, textDecoration = "bold", border = c("top", "bottom", "left", "right"), borderStyle = "thin", wrapText = TRUE, halign = "center"), character = openxlsx::createStyle(fontSize = 12, border = c("top", "bottom", "left", "right"), borderStyle = "thin"), number = openxlsx::createStyle(fontSize = 12, numFmt = "### ### ### ##0", border = c("top", "bottom", "left", "right"), borderStyle = "thin"), decimal = openxlsx::createStyle(fontSize = 12, numFmt = "### ### ### ##0.0", border = c("top", "bottom", "left", "right"), borderStyle = "thin"), percent = openxlsx::createStyle(fontSize = 12, numFmt = "#0.0", border = c("top", "bottom", "left", "right"), borderStyle = "thin", halign = "center"), mergedcell = openxlsx::createStyle(fontSize = 12, border = c("top", "bottom", "left", "right"), borderStyle = "thin", wrapText = TRUE, valign = "center", halign = "center"), ... )
title |
Style for the title |
footnote1 |
Style for footnote1 |
footnote2 |
Style for footnote2 |
footnote3 |
Style for footnote3 |
col_header |
Style for the columns header |
character |
Default style for data cells |
number |
Style for columns in number format |
decimal |
Style for columns in decimal format |
percent |
Style for columns in percent format |
mergedcell |
Style for merged cells |
... |
Other (named) custom styles |
a named list of class xls_theme, whose elements are 'openxlsx' Style objects.
xls_theme()
,
xls_theme_plain()
# default theme xls_theme_default() # default theme with title in italic my_theme <- xls_theme_default(title = openxlsx::createStyle(textDecoration = "italic")) ## Not run: toxlsx(object = iris, path = tempdir(), theme = my_theme) ## End(Not run)
# default theme xls_theme_default() # default theme with title in italic my_theme <- xls_theme_default(title = openxlsx::createStyle(textDecoration = "italic")) ## Not run: toxlsx(object = iris, path = tempdir(), theme = my_theme) ## End(Not run)
This function is a wrapper around [xls_theme()] that creates an xls theme for styling exported tables. It defines a simple theme whith no special formatting. All its arguments must be 'openxlsx' Style objects.
xls_theme_plain( title = openxlsx::createStyle(), col_header = openxlsx::createStyle(), character = openxlsx::createStyle(), footnote1 = openxlsx::createStyle(), footnote2 = openxlsx::createStyle(), footnote3 = openxlsx::createStyle(), mergedcell = openxlsx::createStyle(), ... )
xls_theme_plain( title = openxlsx::createStyle(), col_header = openxlsx::createStyle(), character = openxlsx::createStyle(), footnote1 = openxlsx::createStyle(), footnote2 = openxlsx::createStyle(), footnote3 = openxlsx::createStyle(), mergedcell = openxlsx::createStyle(), ... )
title |
Style for the title |
col_header |
Style for the columns header |
character |
Default style for data cells |
footnote1 |
Style for footnote1 |
footnote2 |
Style for footnote2 |
footnote3 |
Style for footnote3 |
mergedcell |
Style for merged cells |
... |
Other (named) custom styles |
a named list of class xls_theme, whose elements are 'openxlsx' Style objects.
xls_theme()
,
xls_theme_default()
# plain theme xls_theme_plain() # plain theme with title in bold my_theme <- xls_theme_plain(title = openxlsx::createStyle(textDecoration = "bold")) ## Not run: toxlsx(object = iris, path = tempdir(), theme = my_theme) ## End(Not run)
# plain theme xls_theme_plain() # plain theme with title in bold my_theme <- xls_theme_plain(title = openxlsx::createStyle(textDecoration = "bold")) ## Not run: toxlsx(object = iris, path = tempdir(), theme = my_theme) ## End(Not run)