Learn R Programming

openxlsx2 (version 0.8)

wb_add_data_table: Add data to a worksheet as an Excel table

Description

Add data to a worksheet and format as an Excel table

Usage

wb_add_data_table(
  wb,
  sheet = current_sheet(),
  x,
  dims = wb_dims(start_row, start_col),
  start_col = 1,
  start_row = 1,
  col_names = TRUE,
  row_names = FALSE,
  table_style = "TableStyleLight9",
  table_name = NULL,
  with_filter = TRUE,
  sep = ", ",
  first_column = FALSE,
  last_column = FALSE,
  banded_rows = TRUE,
  banded_cols = FALSE,
  apply_cell_style = TRUE,
  remove_cell_style = FALSE,
  na.strings = na_strings(),
  inline_strings = TRUE,
  ...
)

Arguments

wb

A Workbook object containing a #' worksheet.

sheet

The worksheet to write to. Can be the worksheet index or name.

x

A dataframe.

dims

Spreadsheet dimensions that will determine start_col and start_row: "A1", "A1:B2", "A:B"

start_col

A vector specifying the starting column to write df

start_row

A vector specifying the starting row to write df

col_names

If TRUE, column names of x are written.

row_names

If TRUE, row names of x are written.

table_style

Any excel table style name or "none" (see "formatting" vignette).

table_name

name of table in workbook. The table name must be unique.

with_filter

If TRUE, columns with have filters in the first row.

sep

Only applies to list columns. The separator used to collapse list columns to a character vector e.g. sapply(x$list_column, paste, collapse = sep).


The below options correspond to Excel table options:
Figure: table_options.png

first_column

logical. If TRUE, the first column is bold

last_column

logical. If TRUE, the last column is bold

banded_rows

logical. If TRUE, rows are color banded

banded_cols

logical. If TRUE, the columns are color banded

apply_cell_style

Should we write cell styles to the workbook

remove_cell_style

keep the cell style?

na.strings

Value used for replacing NA values from x. Default na_strings() uses the special #N/A value within the workbook.

inline_strings

write characters as inline strings

...

additional arguments

Details

columns of x with class Date/POSIXt, currency, accounting, hyperlink, percentage are automatically styled as dates, currency, accounting, hyperlinks, percentages respectively. The string "_openxlsx_NA" is reserved for openxlsx2. If the data frame contains this string, the output will be broken.

See Also

Other workbook wrappers: wb_add_chartsheet(), wb_add_data(), wb_add_formula(), wb_add_pivot_table(), wb_add_worksheet(), wb_base_font, wb_clone_worksheet(), wb_col_widths, wb_copy_cells(), wb_creators, wb_freeze_pane(), wb_grouping, wb_merge_cells(), wb_save(), wb_set_last_modified_by(), wb_set_row_heights(), wb_workbook()