Reading Excel: evaluation error with zip file '..file.xlsx' cannot be opened

依然范特西╮ 提交于 2019-12-19 12:38:24

问题


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

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

It says 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?


回答1:


The error message is readxl's funny way of saying "file not found". That exact line of code gives me the exact same error, and the file doesn't even exist for me.

Note: I'm on version 1.0.0 of readxl




回答2:


I had this error, but for me, it was just that I had the sheet open in Excel while trying to read it into R. I guess the package wrongly perceives it as a zip file when it's trying to read it while Excel has partial ownership of it (and this blocks the read).




回答3:


You can specify a path to a file, only if it is nested on the working directory. For example: If your working directory is MyWD and there is a folder in it, named MyData and another folder within MyData named 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



回答4:


If your excel worksheet is password protected, read_excel won't be able to access it and will give you this error. If it needs protection, I would suggest p/w protecting the folder it's in, and then unprotecting the worksheet.




回答5:


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

setwd("C:\\map\\map_in_map\\map_in_map_in_map_where_the_file_is")



回答6:


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



来源:https://stackoverflow.com/questions/44619585/reading-excel-evaluation-error-with-zip-file-file-xlsx-cannot-be-opened

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!