To get Excel or Workbook file sheet names using R xlsx
Download your workbook or Excel file, in my case, for example, the name of the Excel file is "input_4_r.xlsx"
> wb<-loadWorkbook("input_4_r.xlsx")
see the list of files, here it shows 2 sheets in my example in my example, I did not name the first sheet and kept the default value, but the 2nd sheet, I called "name city" and therefore the output below
> getSheets(wb) $Sheet1 [1] "Java-Object{Name: /xl/worksheets/sheet1.xml - Content Type: application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml}" $'name city' [1] "Java-Object{Name: /xl/worksheets/sheet2.xml - Content Type: application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml}"
You can see the sheet name names as below
> names(getSheets(wb)) [1] "Sheet1" "name city"
to get the name of a specific index of the sheet, for example, passing [2] in my case for the 2nd sheet
> names(getSheets(wb))[2] [1] "name city"
*** It is assumed that the xlsx package is installed and downloaded to R.
Ashutosh
source share