Learn R Programming

openxlsx2 (version 0.4.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),
  xy = NULL,
  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
)

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"

xy

An alternative to specifying startCol and startRow individually. A vector of the form c(startCol, startRow)

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 colour banded

bandedCols

logical. If TRUE, the columns are colour banded

applyCellStyle

Should we write cell styles to the workbook

removeCellStyle

keep the cell style?

na.strings

optional

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_worksheet(), wb_clone_worksheet(), 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