首页 文章

在r中打开/读取excel文件

提问于
浏览
0

我无法打开/阅读我使用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 但我工作了 .

我试图使用 download.file 函数下载文件,注意设置 mode = wb ,但这对于能够访问工作簿中的数据没有任何区别 .

感谢任何指针 .

2 回答

  • 0

    你试过其他包吗?如果我手动下载文件并使用 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
    
  • 0

    它适用于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")
    

相关问题