I have loaded a workbook into R and read in the worksheets using xlConnect, but I was wondering if there was a way of extracting the names of the sheets perhaps in a vector?
So far my code is:
dataIn<-loadWorkbook(file.path(filenames[1],sep="")) lst = readWorksheet(dataIn, sheet = getSheets(dataIn), startRow=1, startCol=1, header=TRUE)
...and I want to extract the sheet names of the sheets in lst
.
It's easy to get the excel sheet names with the excel_sheets() function. Show activity on this post. Returns all worksheet names in a workbook. Show activity on this post.
The read. xlsx method is used to read data from an Excel file or Workbook object into an R data. frame object over the specified file path. In this case, the lapply() method takes as input the sheet names and returns the corresponding data frames belonging to each sheet of the workbook.
Another really nice package developed by the folks at RStudio is readxl
. It's easy to get the excel sheet names with the excel_sheets()
function.
library(readxl) path <- "path/to/your/file.xlsx" excel_sheets(path = path)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With