R read_excel:libxls错误:无法解析文件 [英] R read_excel: libxls error: Unable to parse file

查看:88
本文介绍了R read_excel:libxls错误:无法解析文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用readxl :: read_excel 将xls文件读取到R中,但是出现以下错误:

I'm trying to read xls file into R using readxl::read_excel, but it's giving the following errors:

Error: 
  filepath: //.../data.xls
  libxls error: Unable to parse file

还尝试了readxl :: excel_sheets(),但存在相同的错误.

also tried readxl::excel_sheets(), but same errors.

  • readxl :: format_from_ext(path)给出"xls"

也尝试重新安装readxl软件包,对我不起作用.

Also tried re-installing readxl packages, didn't work for me.

我当前的替代方法是使用Excel将文件转换为"xlsx",然后使用readxl :: read_excel进行读取,但是我想直接导入"xls".

My current alternative is to convert this file to "xlsx" using Excel and then read in with readxl::read_excel, but I would like to import the "xls" directly.

如何解决?

推荐答案

我遇到了很多这个问题(完全相同的错误消息),这似乎与保存.xls文件的方式有关.或导出.例如.在excel中,如果您检查工作表,有时会出现警告.但是,当您有自动化文件或需要由R打开的大量文件时,检查或重新保存是不实际的.我有一些示例.xls文件,无论如何,它们都无法通过readxl,openxlsx库加载我尝试的选项(例如,指定工作表,这通常可以解决加载excel工作表的问题).我终于通过简单地使用XLConnect包解决了这个问题(请注意,它确实需要安装Java).您没有示例文件,我无法共享正在处理的文件,但是请尝试

I've come across this problem a lot (exact same error message) and it seems to be something to do with the way the .xls file has been saved or exported. Eg. in excel if you inspect the sheet it sometimes turns up warnings. However, inspection or re-saving is not practical when you have automated files, or a huge number of files which you need opened by R. I have some example .xls files that fail to be loaded by readxl, openxlsx libraries, no matter what options I try (for example, specifying sheet, which often solves the problem of loading excel sheets). I have solved this problem finally, by simply using the XLConnect package (note that it does require Java to be installed). You don't have a sample file, and I can't share the ones I am working on, but try this

install.packages('XLConnect')
library(XLConnect)
# to load sheet one of 'test.xls', and my sheet does not have a header
# method one, read workbook, followed by worksheet
f <- loadWorkbook('test.xls')
d <- readWorksheet(f, 1, header = F)
# method two, read sheet directly into your dataframe
d <- readWorksheetFromFile ('test.xls', 1, header = F)

这篇关于R read_excel:libxls错误:无法解析文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆