Read data from an Excel file or Workbook object into a data.frame
Usage
wb_read(
xlsxFile,
sheet = 1,
startRow = 1,
startCol = NULL,
rowNames = FALSE,
colNames = TRUE,
skipEmptyRows = FALSE,
skipEmptyCols = FALSE,
rows = NULL,
cols = NULL,
detectDates = TRUE,
namedRegion,
na.strings = "NA",
na.numbers = NA,
...
)
Arguments
- xlsxFile
An xlsx file, Workbook object or URL to xlsx file.
- sheet
The name or index of the sheet to read data from.
- startRow
first row to begin looking for data.
- startCol
first column to begin looking for data.
- rowNames
If
TRUE
, first column of data will be used as row names.- colNames
If
TRUE
, the first row of data will be used as column names.- skipEmptyRows
If
TRUE
, empty rows are skipped else empty rows after the first row containing data will return a row of NAs.- skipEmptyCols
If
TRUE
, empty columns are skipped.- rows
A numeric vector specifying which rows in the Excel file to read. If NULL, all rows are read.
- cols
A numeric vector specifying which columns in the Excel file to read. If NULL, all columns are read.
- detectDates
If
TRUE
, attempt to recognize dates and perform conversion.- namedRegion
A named region in the Workbook. If not NULL startRow, rows and cols parameters are ignored.
- na.strings
A character vector of strings which are to be interpreted as NA. Blank cells will be returned as NA.
- na.numbers
A numeric vector of digits which are to be interpreted as NA. Blank cells will be returned as NA.
- ...
additional arguments passed to
wb_to_df()
Examples
xlsxFile <- system.file("extdata", "openxlsx2_example.xlsx", package = "openxlsx2")
df1 <- wb_read(xlsxFile = xlsxFile, sheet = 1)
xlsxFile <- system.file("extdata", "openxlsx2_example.xlsx", package = "openxlsx2")
df1 <- wb_read(xlsxFile = xlsxFile, sheet = 1, rows = c(1, 3, 5), cols = 1:3)