Accessing Excel file from Sharepoint with R

馋奶兔 提交于 2019-11-27 03:52:57

问题


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.


回答1:


I use

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

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)

Peter A




回答2:


Try using the link in this format: http://site/_layouts/download.aspx?SourceUrl=url-of-document-in-library




回答3:


You may need to map a network drive to the SharePoint library so that you can connect to it directly. Or if you don't want to map a network drive you could also place a shortcut to the folder in your startup folder.

Example file path: \company_sharepoint_site\ssp\site_name\sub_site_name\library_name

Example start up folder location (Windows 10): C:\Users\USER_NAME\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup

Note direction of the slashes ("\" rather than "/") is important so that your file path is interpreted as a file location, not an internet browser location. By placing such a path in a network drive or as a shortcut in your startup folder your PC should connect to it when it boots.

 # Load or install readxl
if(require(readxl) == FALSE){
  install.packages("readxl")
  if(require(readxl)== FALSE){stop("Unable to install and load readxl")}
}

# Define path to data 
data_path <- "\\\\company_sharepoint_site\\ssp\\site_name\\sub_site_name\\library_name\\Example.xlsx"

# Pull data
df_employees <- read_xlsx(data_path)


来源:https://stackoverflow.com/questions/28048979/accessing-excel-file-from-sharepoint-with-r

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!