write_xlsx: Write a dataframe to an excel spreadsheet sheet.

View source: R/xlsx.R

write_xlsxR Documentation

Write a dataframe to an excel spreadsheet sheet.

Description

I like to give folks data in any format they prefer, even though I sort of hate excel. Most people I work with use it, so therefore I do too. This function has been through many iterations, first using XLConnect, then xlsx, and now openxlsx. Hopefully this will not change again.

Usage

write_xlsx(
  data = NULL,
  wb = NULL,
  sheet = "first",
  excel = NULL,
  rownames = TRUE,
  start_row = 1,
  start_col = 1,
  title = NULL,
  float_format = "0.000",
  data_table = TRUE,
  freeze_first_row = TRUE,
  freeze_first_column = TRUE,
  date_format = "yyyy-mm-dd",
  column_width = "heuristic",
  ...
)

Arguments

data

Data frame to print.

wb

Workbook to which to write.

sheet

Name of the sheet to write.

excel

Filename of final excel workbook to write

rownames

Include row names in the output?

start_row

First row of the sheet to write. Useful if writing multiple tables.

start_col

First column to write.

title

Title for this xlsx table.

float_format

Revisit this, but it hard-sets the number of decimal points in floating point columns.

data_table

Write this as an excel data table instead of just a collection of cells.

freeze_first_row

Add a hint to make the first row always on screen?

freeze_first_column

Add a hint to make the first column always on screen?

date_format

Coerce date columns to this format.

column_width

Either a specific value, NULL, or 'heuristic' which guesses.

...

Set of extra arguments given to openxlsx.

Value

List containing the sheet and workbook written as well as the bottom-right coordinates of the last row/column written to the worksheet.

See Also

[openxlsx] [openxlsx::createWorkbook()] [openxlsx::writeData()] [openxlsx::writeDataTable()] [openxlsx::saveWorkbook()]

Examples

 ## Not run: 
  xls_coords <- write_xlsx(dataframe, sheet = "hpgl_data", excel = "testing.xlsx")
  xls_coords <- write_xlsx(another_df, wb = xls_coords$workbook,
                          sheet = "hpgl_data", start_row = xls_coords$end_col)
 
## End(Not run)

elsayed-lab/hpgltools documentation built on May 9, 2024, 5:02 a.m.