【问题标题】:Opening/reading an excel file in r在 r 中打开/读取 excel 文件
【发布时间】:2019-01-05 17:25:43
【问题描述】:

我无法打开/阅读使用 readxl 从澳大利亚统计局网站下载的 excel 文件。

我有来自网站的downloaded Table 12,但是当我去阅读r 中的工作簿时,我收到一条错误消息:

library(readxl)    
excel_sheets(path = "C:/Users/Name/Documents/downloaded_file.xls")

"Error in xls_sheets(path) : Failed to open C:/Users/Name/Documents/downloaded_file.xls".

在以前的readxl 版本中,我可以毫无困难地将这些文件读入r,但我最近更新了我的readxl 版本,经过几个月的中断,现在它不起作用了。

我已尝试使用 download.file 函数下载文件,并注意设置 mode = wb,但这对于访问工作簿中的数据也没有影响。

感谢任何指点。

【问题讨论】:

  • 该文件是"Composite Document File V2 Document",因此它包含除普通excel数据之外的“流”。听起来有人在这个文件上或附近做了一些“高级创作”:-)。我不熟悉 R 中读取它的工具,也不熟悉任何可能为您分离流的(非 R)工具。
  • 感谢@r2evans。你是怎么解决的?
  • 下载并运行file 6202001.xls,它报告了格式。我没有尝试过同一页面上的任何其他文件,所以这可能只是一个一次性问题,工作人员在处理文件时不小心搞砸了。如果你有一种机制可以询问他们,也许他们可以重新生成或修复文件。

标签: r excel readxl


【解决方案1】:

您是否尝试过其他软件包。如果我手动下载文件并使用xlsx 阅读它,它对我有用。下面是您需要的输出还是我遗漏了什么?

library("xlsx")
# there is certainly a better (faster) way to get the sheet number
n_sheets =  length(getSheets(loadWorkbook("6202012.xls")))
# if you know which sheet to load, reading the sheet works for me...
df = read.xlsx("6202012.xls", 2)
df[1:3, 1:3]
#            NA. Employed.total....Persons....Australia.. Employed.total....Persons....Australia...1
# 1        Unit                                      000                                        000
# 2 Series Type                                    Trend                        Seasonally Adjusted
# 3   Data Type                                    STOCK                                      STOCK

【讨论】:

    【解决方案2】:

    它适用于 Windows:

    library(readxl)    
    excel_sheets(path = "C:/Users/Name/Documents/downloaded_file.xls")
    data<-readxl::read_excel(path = ""C:/Users/Name/Documents/downloaded_file.xls"",sheet = "Data1")
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-12-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-05-30
      • 2012-10-05
      • 2019-11-08
      • 1970-01-01
      相关资源
      最近更新 更多