我公司的 sharepint 文件夹中有一些文件。我需要使用 r 下载该文件夹中的所有文件。我怎样才能用 R 做到这一点?
我用谷歌搜索了这个问题并得到了这个链接。这是关于将文件上传到共享点文件夹。 [从 R 上传文件到 SharePoint
链接中的代码如下:
saveToSharePoint <- function(fileName)
{
cmd <- paste("curl --max-time 7200 --connect-timeout 7200 --ntlm --user","username:password",
"--upload-file /home/username/FolderNameWhereTheFileToTransferExists/",fileName,
"teamsites.OrganizationName.com/sites/PageTitle/Documents/UserDocumentation/FolderNameWhereTheFileNeedsToBeCopied/",fileName, sep = " ")
system(cmd)
}
saveToSharePoint("SomeFileName.Ext")
这是关于上传一个特定文件。但我需要的是从共享点文件夹下载文件。
所以,我修改了代码以从共享点文件夹复制。我将
--upload-file
更改为--download-file
。
copyFromSharePoint <- function(fileName)
{
cmd <- paste("curl --max-time 7200 --connect-timeout 7200 --ntlm --user","username:password",
"--download-file teamsites.OrganizationName.com/sites/PageTitle/Documents/FolderNameWhereTheFileToTransferExists/",fileName,
"home/username/UserDocumentation/FolderNameWhereTheFileNeedsToBeCopied/",fileName, sep = " ")
system(cmd)
}
copyFromSharePoint("SomeFileName.Ext")
然而,这似乎不起作用。错误信息如下:
curl: option --download-file: is unknown
有谁知道我如何用 R 做到这一点?
另外,如果我需要下载文件夹中的所有文件,而不是某个特定文件怎么办。有谁知道我如何用 R 来做到这一点?
我制作了一个名为 sharepointr 的简单 R 包,用于从 SharePoint 上传和下载文件。
我从 R 进行整个下载/上传到共享点工作的方法是:
包里都有描述 Readme.md
# Installing the package
install.packages("devtools")
devtools::install_github("esbeneickhardt/sharepointr")
# Setting parameters
client_id <- "insert_from_first_step"
client_secret <- "insert_from_first_step"
tenant_id <- "insert_from_fourth_step"
resource_id <- "insert_from_fourth_step"
site_domain <- "yourorganisation.sharepoint.com"
sharepoint_url <- "https://yourorganisation.sharepoint.com/sites/MyTestSite"
# Getting a SharePoint Token
sharepoint_token <- get_sharepoint_token(client_id, client_secret, tenant_id, resource_id, site_domain)
# Getting sharepoint digest value
sharepoint_digest_value <- get_sharepoint_digest_value(sharepoint_token, sharepoint_url)
# Downloading a file
sharepoint_path <- "Shared Documents/test"
sharepoint_file_name <- "Mappe.xlsx"
out_path <- "C:/Users/User/Desktop/"
download_sharepoint_file(sharepoint_token, sharepoint_url, sharepoint_digest_value, sharepoint_path, sharepoint_file_name, out_path)
这是一种可以使用 R 下载 Word 文件的方法:
library(RDCOMClient)
wordApp <- COMCreate("Word.Application")
wordApp[["Visible"]] <- TRUE
url <- "https://XXXX.sharepoint.com/.../my_Word_File.docx"
doc <- wordApp[["Documents"]]$Open(url)
doc$SaveAs("C:\\Downloads\\my_Word_File.docx")
同样的方法也可用于 Excel。