How to extract sheet names from Excel file in R

userk picture userk · Jul 30, 2013 · Viewed 36.6k times · Source

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.

Answer

Matt Dancho picture Matt Dancho · Jul 1, 2017

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)