本文介绍了在R中读取.xls文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将.xls文件读入R数据帧.我尝试过:

 库(readxl)dfTest<-readxl :: read_excel("file_path/file.xls") 

哪个给我:

 错误:文件路径:file_path/file.xlslibxls错误:无法打开文件 

接下来我尝试了

 库(xlsx)dfTest<-xlsx :: read.xlsx("file_path/file.xls",1) 

这将导致:

.jcall("RJavaTools","Ljava/lang/Object;","invokeMethod",cl 、:java.io.IOException:块[1462]已被删除-您的POIFS是否具有循环或重复的块引用?

我尝试过:

 库(openxlsx)dfTest<-openxlsx :: read.xlsx("file_path/file.xls") 

这将导致:

  read.xlsx.default("file_path/file.xls")中的错误:openxlsx无法读取.xls或.xlm文件! 

我最后尝试的是:

 库(RODBC)conn--odbcConnectExcel("file_path/file.xls") 

哪个给我:

odbcConnectExcel(" file_path/file.xls")中的

 错误:odbcConnectExcel仅适用于32位Windows 

有人会知道我如何读取Excel文件吗?将文件另存为.csv文件并将其加载到R中可以很好地工作.但是,我有大量的文件,最终我要循环读取和处理这些文件.至少可以说,手动将所有内容保存为.csv很有意思.在更改正在使用的计算机上的软件安装方面,我受到限制.

解决方案

我认为对于.xls文件,来自readr包的read_delim应该可以工作.

例如:

  readr :: read_delim("file_path/file.xls",as.is = TRUE) 

I am trying to read a .xls-file into a R dataframe. I've tried:

library(readxl)
dfTest <- readxl::read_excel("file_path/file.xls")

Which gives me:

Error:
filepath: file_path/file.xls
libxls error: Unable to open file

Next I tried:

library(xlsx)
dfTest <- xlsx::read.xlsx("file_path/file.xls",1)

Which results in:

Error in .jcall("RJavaTools", "Ljava/lang/Object;", "invokeMethod", cl,  :
  java.io.IOException: block[ 1462 ] already removed - does your POIFS have circular or duplicate block references?

I tried:

library(openxlsx)
dfTest <- openxlsx::read.xlsx("file_path/file.xls")

Which results in:

Error in read.xlsx.default("file_path/file.xls") :
  openxlsx can not read .xls or .xlm files!

Last thing that I tried was:

library(RODBC)
conn <- odbcConnectExcel("file_path/file.xls")

Which gives me:

Error in odbcConnectExcel("file_path/file.xls") :
  odbcConnectExcel is only usable with 32-bit Windows

Would anyone have an idea how I can read the Excel file? Saving the file as .csv-file and loading it into R works perfectly fine. However, I have a large amount of files that I ultimately want to read and process in a loop. Saving all by hand as .csv is teadious to say the least.I'm restricted in changing the software installations on the computer I'm working on.

解决方案

I believe for .xls files read_delim from the readr package should work.

For example:

readr::read_delim("file_path/file.xls",as.is=TRUE)

这篇关于在R中读取.xls文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-23 00:25