How to extract sheet names from Excel file in R

2020-01-31 18:30发布

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.

4条回答
冷血范
2楼-- · 2020-01-31 19:14

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)
查看更多
小情绪 Triste *
3楼-- · 2020-01-31 19:22

In the "openxlsx" package it would be a command "getSheetNames":

library(openxlsx)
path <- "path/to/your/file.xlsx"
getSheetNames(path)
查看更多
走好不送
4楼-- · 2020-01-31 19:23
dataIn <-loadWorkbook(file.path(filenames[1], sep=""))

sheet <- getsheets(dataIn)

To get the 1st sheet use sheet[1]

查看更多
Emotional °昔
5楼-- · 2020-01-31 19:31

You are looking for getSheets

Returns all worksheet names in a workbook.
查看更多
登录 后发表回答