Learn R Programming

openxlsx (version 1.0.3)

read.xlsx: Read data from a worksheet into a data.frame

Description

Read data from a worksheet into a data.frame

Usage

read.xlsx(xlsxFile, sheet = 1, startRow = 1, colNames = TRUE)

Arguments

xlsxFile
A xlsx workbook
sheet
The name or index of the sheet to read data
startRow
startRow is used to specify where to begin looking for data. Empty rows will be skipped regardless of the value of startRow.
colNames
IF TRUE, will attempt to look for column names.

Value

  • data.frame

Details

Creates a data.frame of all data in worksheet. If the first row of data consists entirely of strings, these will be used as column names.

See Also

readWorkbook

Examples

Run this code
xlsxFile <- system.file("readTest.xlsx", package = "openxlsx")
system.time({df1 <- read.xlsx(xlsxFile = xlsxFile, sheet = 1)})
system.time({df2 <- read.xlsx(xlsxFile = xlsxFile, sheet = 2)})
system.time({df3 <- read.xlsx(xlsxFile = xlsxFile, sheet = 3)}) ## empty columns are skipped
system.time({df4 <- read.xlsx(xlsxFile = xlsxFile, sheet = 4)}) ## Numeric columns are padded with 0
system.time({df5 <- read.xlsx(xlsxFile = xlsxFile, sheet = 5, startRow = 2)})
system.time({df6 <- read.xlsx(xlsxFile = xlsxFile, sheet = 6)}) ## NULL
system.time({df7 <- read.xlsx(xlsxFile = xlsxFile, sheet = 7)})
system.time({df8 <- read.xlsx(xlsxFile = xlsxFile, sheet = 8)}) ##

Run the code above in your browser using DataLab