to_excel: Pass data to Excel workbooks

Description Usage Arguments Note Author(s) Examples

Description

to_excel allows you to pass R objects (primarily a data.frame) to an open Workbook, and write it later with write_data. The workbook can be created by calling excel_workbook, which is itself a wrapper for createWorkbook.

Usage

1
2
3
4
5
6
7
to_excel(df, wb, title = NULL, ...)

excel_workbook(template = NULL)

## S3 method for class 'data.frame'
to_excel(df, wb, title = NULL, sheet = "tables",
  format = TRUE, append = TRUE, row = 1L, col = 1L, ...)

Arguments

df

A data.frame, table or matrix.

wb

A Workbook.

title

The title to give to the table. When NULL (the default), to_excel will use the 'title' attribute of the object, or a single whitespace if attr(x, 'title') returns NULL as well.

...

Arguments passed to to_excel.data.frame (See below).

template

Optional: Specify a path if you would like to append data to an existing .xlsx file. Default creates a new workbook.

sheet

The sheet you want to write the data to.

format

Format values and apply the default template to the table output.

append

Whether or not the function should append to or replace the sheet before writing.

row

Specify the startingrow when writing data to a new sheet.

col

Start column. Same as for row.

Note

This function requires openxlsx.

Author(s)

Kristian D. Olsen

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
if (require(openxlsx)) {
 wb <- excel_workbook()
 df <- data.frame("String" = c("A", "B"), "Int" = c(1:2L), "Percent" = c(0.5, 0.75))

 # The workbook is mutable, so we don't have to assign result.
 to_excel(df, wb, title = "Example data", sheet = "Example", append = FALSE)

 # Data is first argument, so we can use it with dplyr.
 # df %>% to_excel(wb, title = "Example dplyr", sheet = "Example", append = TRUE)

 # Save the data
 write_data(wb, "Example table.xlsx", overwrite = TRUE)
}

itsdalmo/seamless documentation built on May 18, 2019, 7:11 a.m.