首页 文章

使用R从Azure blob导入excel

提问于
浏览
1

我按照以下链接完成了基本设置:

http://htmlpreview.github.io/?https://github.com/Microsoft/AzureSMR/blob/master/inst/doc/tutorial.html

有一个方法'azureGetBlob',它允许您从容器中检索对象 . 但是,它似乎只允许“原始”和“文本”格式,这对excel不是很有用 . 我已经测试了连接等,我可以检索.txt / .csv文件,但不能检索.xlsx文件 .

有谁知道任何解决方法吗?

谢谢

2 回答

  • 0

    解决了以下代码 . 基本上,以字节读取文件然后将文件写入磁盘然后将其读入R

    excel_bytes <- azureGetBlob(sc, storageAccount = "accountname", container = "containername", blob=blob_name, type="raw") 
    q <- tempfile()
    f <- file(q, 'wb')
    writeBin(excel_bytes, f)
    close(f)
    result <- read.xlsx(q, sheetIndex = sheetIndex)
    unlink(q)
    
  • 0

    有谁知道任何解决方法吗?

    azure blob存储上没有文件类型,它只是一个blob名称 . 扩展类型以OS而闻名 . 如果我们想在r中打开excel文件,我们可以使用第三个库来执行此操作,例如readXl .

    Work around:

    您可以使用get blob api将blob文件下载到本地路径,然后使用readXl读取文件 . 我们还可以从这个link获得更多的演示代码 .

    # install
    install.packages("readxl")
    # Loading
    library("readxl")
    # xls files
    my_data <- read_excel("my_file.xls")
    # xlsx files
    my_data <- read_excel("my_file.xlsx")
    

相关问题