使用 R 从 Sharepoint 访问 Excel 文件 [英] Accessing Excel file from Sharepoint with R

查看:60
本文介绍了使用 R 从 Sharepoint 访问 Excel 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写一个 R 脚本,该脚本将访问存储在我公司的 Sharepoint 页面上的 Excel 文件,以便我可以进行一些计算并绘制结果.我已经尝试了各种方法来做到这一点(download.file、RCurl getURL()、gdata),但我似乎无法弄清楚如何做到这一点.网址是 HTTPS,应该需要用户名和密码.我最接近此代码:

am trying to write an R script that will access an Excel file that is stored on my company's Sharepoint page so that I can make a few calculations and plot the results. I've tried various ways to do this (download.file, RCurl getURL(), gdata), but I can't seem to figure out how to do this. The url is HTTPS and there should be a username and password required. I've gotten the closest with this code:

require(RCurl)
URL<-"https://companyname.sharepoint.com/sites/folder/_layouts/15/WopiFrame.aspx?sourcedoc={2DCC2ED7-1C13-4910-AFAD-4A9ACFF1C797}&file=myfile.xlsx&action=default'  
f<-getURL(URL,verbose=T,ssl.verifyhost=F,ssl.verifypeer=F,userpwd="mylogin:mypw") 

这似乎连接(虽然用户名和密码似乎无关紧要)并返回

This seems to connect (although the username and password don't seem to matter) and returns

> f  
[1] "<html><head><title>Object moved</title></head><body>\r\n<h2>Object moved to <a href=\"https://companyname.sharepoint.com/sites/_layouts/15/WopiFrame2.aspx?sourcedoc={2DCC2ED7-1C13-4910-AFAD-4A9ACFF1C797}&amp;file=MyFile.xlsx&amp;action=default\">here</a>.</h2>\r\n</body></html>\r\n"`

但是,我不知道此时该做什么,或者即使我在正确的轨道上.任何帮助将不胜感激.

However, I'm not sure what to do at this point, or even if I'm on the right track. Any help will be greatly appreciated.

推荐答案

我用

library(readxl)
read_excel('//companySharepointSite/project/.../ExcelFilename.xlsx', 'Sheet1', skip=1)

注意,没有https:,有时我必须先打开文件(即剪切和粘贴//companySharepointSite/project/.../ExcelFilename.xlsx 进入我浏览器的地址栏)

Note, no https:, and sometimes I have to open the file first (i.e., cut and paste //companySharepointSite/project/.../ExcelFilename.xlsx into my browser's address bar)

这篇关于使用 R 从 Sharepoint 访问 Excel 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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