How to extract sheet names from Excel file in R

旧街凉风 提交于 2019-11-26 23:13:04

问题


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.


回答1:


You are looking for getSheets

Returns all worksheet names in a workbook.



回答2:


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)



回答3:


dataIn <-loadWorkbook(file.path(filenames[1], sep=""))

sheet <- getsheets(dataIn)

To get the 1st sheet use sheet[1]



来源:https://stackoverflow.com/questions/17944777/how-to-extract-sheet-names-from-excel-file-in-r

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!