Movatterモバイル変換


[0]ホーム

URL:


Skip to contents

Write data to an xlsx file

Source:R/write_xlsx.R
write_xlsx.Rd

Write a data frame or list of data frames to an xlsx file.

Usage

write_xlsx(x,file, as_table=FALSE,...)

Arguments

x

An object or a list of objects that can be handled bywb_add_data() to write to file.

file

An optional xlsx file name. If no file is passed, the object is not written to disk and only a workbook object is returned.

as_table

IfTRUE, will write as a data table, instead of data.

...

Arguments passed on towb_workbook,wb_add_worksheet,wb_add_data_table,wb_add_data,wb_freeze_pane,wb_set_col_widths,wb_save,wb_set_base_font

creator

Creator of the workbook (your name). Defaults to login username oroptions("openxlsx2.creator") if set.

sheet

A name for the new worksheet

grid_lines

A logical. IfFALSE, the worksheet grid lines will behidden.

tab_color

Color of the sheet tab. Awb_color(), a valid color (belonging togrDevices::colors()) or a valid hex color beginning with "#".

zoom

The sheet zoom level, a numeric between 10 and 400 as apercentage. (A zoom value smaller than 10 will default to 10.)

total_row

logical. With the defaultFALSE no total row is added.

start_col

A vector specifying the starting column to writex to.

start_row

A vector specifying the starting row to writex to.

col_names

IfTRUE, column names ofx are written.

row_names

IfTRUE, the row names ofx are written.

na.strings

Value used for replacingNA values fromx. Defaultlooks ifoptions(openxlsx2.na.strings) is set. Otherwisena_strings()uses the special#N/A value within the workbook.

first_active_row

Top row of active region

first_active_col

Furthest left column of active region

first_row

IfTRUE, freezes the first row (equivalent tofirst_active_row = 2)

first_col

IfTRUE, freezes the first column (equivalent tofirst_active_col = 2)

widths

Width to setcols to specified column width or"auto" forautomatic sizing.widths is recycled to the length ofcols. openxlsx2sets the default width is 8.43, as this is the standard in some spreadsheetsoftware. SeeDetails for general information on column widths.

overwrite

IfFALSE, will not overwrite whenfile already exists.

font_size

Font size

font_color

Font color

font_name

Name of a font

Value

A workbook object

Details

columns ofx with classDate orPOSIXt are automaticallystyled as dates and datetimes respectively.

Examples

## write to working directorywrite_xlsx(iris, file=temp_xlsx(), col_names=TRUE)write_xlsx(iris,  file=temp_xlsx(),  col_names=TRUE)## Lists elements are written to individual worksheets, using list names as sheet names if availablel<-list("IRIS"=iris,"MTCARS"=mtcars,matrix(runif(1000), ncol=5))write_xlsx(l,temp_xlsx(), col_widths=c(NA,"auto","auto"))## different sheets can be given different parameterswrite_xlsx(l,temp_xlsx(),  start_col=c(1,2,3), start_row=2,  as_table=c(TRUE,TRUE,FALSE), with_filter=c(TRUE,FALSE,FALSE))# specify column widths for multiple sheetswrite_xlsx(l,temp_xlsx(), col_widths=20)write_xlsx(l,temp_xlsx(), col_widths=list(100,200,300))write_xlsx(l,temp_xlsx(), col_widths=list(rep(10,5),rep(8,11),rep(5,5)))# set base font color to automatic so LibreOffice dark mode works as expectedwrite_xlsx(l,temp_xlsx(), font_color=wb_color(auto=TRUE))

[8]ページ先頭

©2009-2025 Movatter.jp