簡體   English   中英

Output SharePoint 文檔庫文件到 CSV 文件使用 Z686155AF75A60A0EDD3F6E9D80C9Z 文件

[英]Output SharePoint Document Library Files to CSV File Using JavaScript

我正在尋找如何將 output SharePoint 文檔庫文件轉換為 csv 文件。 我找到了幾乎可以讓我到達那里的腳本,但我不知道如何更新代碼以將信息導出到 csv 文件而不是 console.log() 或 alert()。 我嘗試的一切都會破壞代碼。 我查看了其他 JavaScript 概念,該概念顯示了如何添加到 CSV 但我再次腳本概念破壞了我試圖修改的代碼。 我正在使用的腳本。 另外,腳本 output 的文件名。 我想獲得有關如何不僅 output 文件名的幫助,而且我喜歡 output、修改日期、創建日期和文件鏈接。 我希望這是可能的,我很感激在實現這個概念方面的任何幫助。 我正在使用的腳本如下。

jQuery(document).ready(function() {
var scriptbase = _spPageContextInfo.webServerRelativeUrl + "/_layouts/15/";
$.getScript(scriptbase + "SP.Runtime.js", function() {
    $.getScript(scriptbase + "SP.js", function() {
        $.getScript(scriptbase + "SP.DocumentManagement.js", createDocumentSet);
        });
    });
});
var docSetFiles;

function createDocumentSet() {
//Get the client context,web and library object.   
clientContext = new SP.ClientContext.get_current();
oWeb = clientContext.get_web();
var oList = oWeb.get_lists().getByTitle("Fact Sheets & Agreements");
clientContext.load(oList);
//Get the root folder of the library   
oLibraryFolder = oList.get_rootFolder();
var documentSetFolder = "sites/nbib/ep/Fact%20Sheets/";
//Get the document set files using CAML query   
var camlQuery = SP.CamlQuery.createAllItemsQuery();
camlQuery.set_folderServerRelativeUrl(documentSetFolder);
docSetFiles = oList.getItems(camlQuery);
//Load the client context and execute the batch   
clientContext.load(docSetFiles, 'Include(File)');
clientContext.executeQueryAsync(QuerySuccess, QueryFailure);
}

function QuerySuccess() {
//Loop through the document set files and get the display name   
var docSetFilesEnumerator = docSetFiles.getEnumerator();
while (docSetFilesEnumerator.moveNext()) {
    var oDoc = docSetFilesEnumerator.get_current().get_file();
    alert("Document Name : " + oDoc.get_name());
    console.log("Document Name : " + oDoc.get_name());
   }
}

function QueryFailure() {
console.log('Request failed - ' + args.get_message());


} 

chrome 中的示例測試腳本。

function QuerySuccess() {
            //Loop through the document set files and get the display name
            var csv = 'Document Name\n';
            var docSetFilesEnumerator = docSetFiles.getEnumerator();
            while (docSetFilesEnumerator.moveNext()) {
                var oDoc = docSetFilesEnumerator.get_current().get_file();
                //alert("Document Name : " + oDoc.get_name());
                //console.log("Document Name : " + oDoc.get_name());
                csv += oDoc.get_name();//+','   if more cloumns
                csv += "\n";
            }
            var hiddenElement = document.createElement('a');
            hiddenElement.href = 'data:text/csv;charset=utf-8,' + encodeURI(csv);
            hiddenElement.target = '_blank';
            hiddenElement.download = 'DocumentList.csv';
            hiddenElement.click();
        }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM