Excel reading: evaluation error with zip file '..file.xlsx' could not be opened

I am using R with readxl package. I am trying to import an Excel file with the following command:

 library(readxl) city_codes <- read_excel("./data/file.xlsx", sheet = "city_codes") 

He says that it is a zip file and cannot be opened:

 Error in sheets_fun(path) : Evaluation error: zip file './data/file.xlsx' cannot be opened. 

Any ideas?

+16
r readxl
source share
6 answers

The readxl error message readxl funny way to say "file not found". This exact line of code gives me the same error, and the file does not even exist for me.

Note. I'm on version 1.0.0 readxl

+11
source share

I had this error, but for me it was just that I opened the worksheet in Excel when I tried to read it in R. I think the package does not correctly interpret it as a mail file when it tries to read it, while Excel has partial ownership of this (and this blocks reading).

+3
source share

You can specify the path to the file only if it is nested in the working directory . For example: if your working directory is MyWD and it has a folder named MyData and another folder in MyData called MyNestedData and finally myExcelFile.xlsx

 read_excel("MyData/MyNestedData/myExcelFile.xlsx",sheet = "Sheet2") #will work read_excel("MyWD/MyData/MyNestedData/myExcelFile.xlsx",sheet = "Sheet2") #will not work 
+1
source share

This can happen if you forget to do the following before using the read_excel function

 setwd("C:\\map\\map_in_map\\map_in_map_in_map_where_the_file_is") 
0
source share

You can try to specify the full path instead of ./path/to/file

0
source share

If your Excel worksheet is password protected, read_excel will not be able to access it and will give you this error. If this requires protection, I would suggest b / w to protect the folder in which it is located, and then unprotect the sheet.

0
source share

All Articles