Import .xlsx File in R Error: Workbook has no worksheets

Viewed 1276

I want to analyze xlsx files generated by a qPCR apparatus with R but I can't open these files unless I save them in excel before loading them in R.

I am using the command read.xlsx() from openxlsx package:

library(openxlsx)
my_file <- "~/my_file.xlsx"
read.xlsx(my_file,1)

I get this message:

Error in read.xlsx.default(my_file, sheet = "0", skipEmptyCols = TRUE) : 
Workbook has no worksheets

The only way this works is if I save the xlsx file first in excel, is there a way to bypass this step?

3 Answers

I think it might be because you haven't called the file by it's proper name? Try;

read.xlsx("my_file.xlsx", sheet = 1)

Open the xlxs file in Excel and allow editing (the yellow bar below the menus) and resave the file. Reload the xlxs in R and see if that fixes it.

library(xlsx)

my_file <- read.xlsx("~/my_file.xlsx",h=T, sheetIndex = 1)

Related