Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extract the number of sheets from an Excel workbook in R (without XLConnect)

Tags:

r

excel

xlconnect

I'm relatively new to R (and programming). I have an Excel workbook with 36 sheets, but suppose that I don't know how many sheets there are and I want my code to find that out for me. I have tried something like:

options(java.parameters = "-Xmx6g")
library(XLConnect)
myWorkbook <- loadWorkbook(filename)
numberofsheets <- length(getSheets(myWorkbook))

But even though I set my memory to 6GB I still run into memory errors with XLConnect, so I would like to use other packages (e.g. xlsx, openxlsx). Is there a way to find out the number of sheets in an Excel workbook without using XLConnect? Thanks for your help.

like image 620
Kaveh Dianati Avatar asked Nov 11 '16 11:11

Kaveh Dianati


People also ask

How do I extract all sheets in Excel?

Using the Move or Copy command will help you export or copy one or several worksheets to a new workbook quickly. Step 1: Select the worksheet names in tab bar. You can select multiple with holding down Ctrl key or shift key. Step 2: Right click the worksheet name, and click the Move or Copy from context menu.


1 Answers

Maybe try:

library( readxl )
length( excel_sheets( filename ) )
like image 174
rosscova Avatar answered Nov 15 '22 19:11

rosscova