Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to extract sheet names from Excel file in R

Tags:

r

excel

xlconnect

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.

like image 703
userk Avatar asked Jul 30 '13 10:07

userk


People also ask

How do I get sheet names in Excel in R?

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.

How do I read an xlsx file in multiple sheets in R?

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.


1 Answers

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) 
like image 100
Matt Dancho Avatar answered Sep 28 '22 10:09

Matt Dancho