Using R to connect to a sharepoint list

前端 未结 3 454
旧时难觅i
旧时难觅i 2020-12-15 23:08

Has anyone been able to import a SharePoint list in R as a dataframe?

I have two separate data sources, one from a SharePoint list and the other from a DB that I wis

3条回答
  •  粉色の甜心
    2020-12-15 23:52

    The answer above works for lists which are <= 1000 rows only. Using "$Top" and "$Skip" in the URL, you can use the function below which iterates multiple times and imports all the data from the list regardless of the size. (This may not be the most clean way to write it, but it works!)

    sp_import <- function(ListName) {
    
            urlstring <- "http://yoursharepointserver/_vti_bin/ListData.svc/yourlist" 
            data <- xmlParse(readLines(paste(urlstring, ListName, sep = ""), warn = FALSE))
            items <- getNodeSet(data, "//m:properties")
            df <- xmlToDataFrame(items, stringsAsFactors = FALSE)
            iterate <- nrow(df)
            skip <- 1
    
            while (nrow(df) == 1000 * skip) {
                data <- xmlParse(readLines(paste(urlstring, ListName, "?$top=1000&$skip=", iterate, sep = ""), warn = FALSE))
                items <- getNodeSet(data, "//m:properties")
                df <- rbind(df, xmlToDataFrame(items, stringsAsFactors = FALSE))
                iterate <- nrow(df)
                skip <- skip + 1
            }
            return(df)
    }
    

提交回复
热议问题