wb_to_df_list() uses openxlsx2::wb_to_df() to extract each sheet of a
workbook object into a data frame. Additional parameters ... are recycled
to match the length of sheet names.
Arguments
- file
A workbook file path, a wbWorkbook object, or a valid URL.
- sheet_names
Character vector of sheet names. If not supplied, all sheet names from the supplied workbook are used.
- ...
Arguments passed on to
openxlsx2::wb_to_dfsheetThe name or index of the worksheet to read. Defaults to the first sheet.
start_row,start_colOptional numeric values specifying the first row or column to begin data discovery.
row_namesLogical; if TRUE, uses the first column of the selection as row names.
col_namesLogical; if TRUE, uses the first row of the selection as column headers.
skip_empty_rows,skip_empty_colsLogical; if TRUE, filters out rows or columns containing only missing values.
skip_hidden_rows,skip_hidden_colsLogical; if TRUE, excludes rows or columns marked as hidden in the worksheet metadata.
rows,colsOptional numeric vectors specifying the exact indices to read.
detect_datesLogical; if TRUE, identifies date and datetime styles for conversion.
naA character vector or a named list (e.g.,
list(strings = "", numbers = -99)) defining values to treat asNA.fill_merged_cellsLogical; if TRUE, propagates the top-left value of a merged range to all cells in that range.
dimsA character string defining the range. Supports wildcards (e.g., "A1:++" or "A-:+5").
show_formulaLogical; if TRUE, returns the formula strings instead of calculated values.
convertLogical; if TRUE, attempts to coerce columns to appropriate R classes.
typesA named vector (numeric or character) to explicitly define column types.
named_regionA character string referring to a defined name or spreadsheet Table.
keep_attributesLogical; if TRUE, attaches metadata such as the internal type table (tt) and types as attributes to the output.
check_namesLogical; if TRUE, ensures column names are syntactically valid R names via
make.names().show_hyperlinksLogical; if TRUE, replaces cell values with their underlying hyperlink targets.
apply_numfmtsLogical; if TRUE, applies spreadsheet number formatting and returns strings.
Examples
wb <- as_wb(list(mtcars[1:3, ], mtcars[4:6, ]))
wb_to_df_list(wb)
#> $`Sheet 1`
#> mpg cyl disp hp drat wt qsec vs am gear carb
#> 2 21.0 6 160 110 3.90 2.620 16.46 0 1 4 4
#> 3 21.0 6 160 110 3.90 2.875 17.02 0 1 4 4
#> 4 22.8 4 108 93 3.85 2.320 18.61 1 1 4 1
#>
#> $`Sheet 2`
#> mpg cyl disp hp drat wt qsec vs am gear carb
#> 2 21.4 6 258 110 3.08 3.215 19.44 1 0 3 1
#> 3 18.7 8 360 175 3.15 3.440 17.02 0 0 3 2
#> 4 18.1 6 225 105 2.76 3.460 20.22 1 0 3 1
#>
wb_to_df_list(wb, "Sheet 1")
#> $`Sheet 1`
#> mpg cyl disp hp drat wt qsec vs am gear carb
#> 2 21.0 6 160 110 3.90 2.620 16.46 0 1 4 4
#> 3 21.0 6 160 110 3.90 2.875 17.02 0 1 4 4
#> 4 22.8 4 108 93 3.85 2.320 18.61 1 1 4 1
#>