使用xlsx [R]在R中打开Excel文件时出错

时间:2022-10-24 13:42:26

This question already has an answer here:

这个问题在这里已有答案:

I recently installed R 3.2.0 (Windows 64 bit) with packages xlsx, which depends on rJava and xlsxjars. Java 1.8.0_11 64 bit is installed on the machine.

我最近安装了包含xlsx的R 3.2.0(Windows 64位),它依赖于rJava和xlsxjars。 Java 1.8.0_11 64位已安装在计算机上。

When I try to use the read.xlsx() function, I get the following error about a zipfile:

当我尝试使用read.xlsx()函数时,我收到有关zipfile的以下错误:

> library(xlsx)
Loading required package: rJava
Loading required package: xlsxjars
> read.xlsx("cameras.xlsx", sheetIndex=1)

Error in .jcall("RJavaTools", "Ljava/lang/Object;", "invokeMethod", cl, : java.util.zip.ZipException: invalid distance too far back

.jcall中的错误(“RJavaTools”,“Ljava / lang / Object;”,“invokeMethod”,cl,:java.util.zip.ZipException:无效距离太远

I sure don't know why it would be trying to unzip anything, unless it is one of the jars that comes with the R packages. (The zip files that the R packages came in unzip fine when I do it by hand.) I've re-installed twice to no avail in case of a corruption there.

我肯定不知道为什么它会尝试解压缩任何东西,除非它是R包附带的罐子之一。 (当我手工完成时,R软件包的zip文件解压缩得很好。)我已经重新安装了两次,但是如果出现腐败,我们无法使用。

I feel like there's a config error somewhere, but I'm really stumped. Has anyone else experienced this? Here are the package install messages

我觉得某处有配置错误,但我真的很难过。还有其他人经历过这个吗?这是包安装消息

> install.packages("xlsx")
Installing package into ‘C:/Users/ggraham412/Documents/R/win-library/3.2’
(as ‘lib’ is unspecified)
also installing the dependencies ‘rJava’, ‘xlsxjars’

trying URL 'http://cran.rstudio.com/bin/windows/contrib/3.2/rJava_0.9-6.zip' 
Content type 'application/zip' length 761928 bytes (744 KB)
downloaded 744 KB

trying URL 'http://cran.rstudio.com/bin/windows/contrib/3.2/xlsxjars_0.6.1.zip'
Content type 'application/zip' length 9485172 bytes (9.0 MB)
downloaded 9.0 MB

trying URL 'http://cran.rstudio.com/bin/windows/contrib/3.2/xlsx_0.5.7.zip'
Content type 'application/zip' length 400857 bytes (391 KB)
downloaded 391 KB

package ‘rJava’ successfully unpacked and MD5 sums checked
package ‘xlsxjars’ successfully unpacked and MD5 sums checked
package ‘xlsx’ successfully unpacked and MD5 sums checked

1 个解决方案

#1


1  

Turns out it was the problem described here: R xlsx package error

原来这是这里描述的问题:R xlsx包错误

Didn't know that xlsx file was accessed by zip library in the above process, and indeed I did not download the spreadsheet as binary.

不知道xlsx文件是在上面的过程中被zip库访问的,事实上我没有将电子表格下载为二进制文件。

#1


1  

Turns out it was the problem described here: R xlsx package error

原来这是这里描述的问题:R xlsx包错误

Didn't know that xlsx file was accessed by zip library in the above process, and indeed I did not download the spreadsheet as binary.

不知道xlsx文件是在上面的过程中被zip库访问的,事实上我没有将电子表格下载为二进制文件。