Learn R Programming

openxlsx2 (version 0.6.1)

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,
  startCol = 1,
  startRow = 1,
  dims = rowcol_to_dims(startRow, startCol),
  colNames = TRUE,
  rowNames = FALSE,
  tableStyle = "TableStyleLight9",
  tableName = NULL,
  withFilter = TRUE,
  sep = ", ",
  firstColumn = FALSE,
  lastColumn = FALSE,
  bandedRows = TRUE,
  bandedCols = FALSE,
  applyCellStyle = TRUE,
  removeCellStyle = 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.

startCol

A vector specifying the starting column to write df

startRow

A vector specifying the starting row to write df

dims

Spreadsheet dimensions that will determine startCol and startRow: "A1", "A1:B2", "A:B"

colNames

If TRUE, column names of x are written.

rowNames

If TRUE, row names of x are written.

tableStyle

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

tableName

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

withFilter

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

firstColumn

logical. If TRUE, the first column is bold

lastColumn

logical. If TRUE, the last column is bold

bandedRows

logical. If TRUE, rows are color banded

bandedCols

logical. If TRUE, the columns are color banded

applyCellStyle

Should we write cell styles to the workbook

removeCellStyle

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

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_clone_worksheet(), wb_copy_cells(), wb_creators, wb_freeze_pane(), wb_get_base_font(), wb_save(), wb_set_col_widths(), wb_set_last_modified_by(), wb_set_row_heights(), wb_workbook(), workbook_grouping, ws_cell_merge