简体   繁体   English

Output SharePoint 文档库文件到 CSV 文件使用 Z686155AF75A60A0EDD3F6E9D80C9Z 文件

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

I'm seeking how to output SharePoint Document Library Files to csv file.我正在寻找如何将 output SharePoint 文档库文件转换为 csv 文件。 I found script that get me almost there, but I can't figure out how to update the code to export the information to a csv file instead to the console.log() or to an alert().我找到了几乎可以让我到达那里的脚本,但我不知道如何更新代码以将信息导出到 csv 文件而不是 console.log() 或 alert()。 Everything I tried breaks the code.我尝试的一切都会破坏代码。 I review other JavaScript concept that shows the how to add out to CSV but I again the script concept breaks the code I'm trying to modify.我查看了其他 JavaScript 概念,该概念显示了如何添加到 CSV 但我再次脚本概念破坏了我试图修改的代码。 The script I am using.我正在使用的脚本。 In addition, the script output the file names.另外,脚本 output 的文件名。 I like to get help on how I can not only output the file name, but I like to output, modified date, created date, and the link to the file.我想获得有关如何不仅 output 文件名的帮助,而且我喜欢 output、修改日期、创建日期和文件链接。 I hope this is possible and I appreciate any help in achieving this concept.我希望这是可能的,我很感激在实现这个概念方面的任何帮助。 Script I'm using follows below.我正在使用的脚本如下。

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());


} 

Sample test script in chrome. 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.

相关问题 如何使用Javascript在Sharepoint 2007文档库中创建新文件 - How to create a new file in Sharepoint 2007 document library using Javascript Sharepoint文档库-使用javascript的标题文件名 - Sharepoint Document Library - Filename to title using javascript 使用JavaScript在SharePoint 2010文档库中创建文档的副本 - Create a copy of document in SharePoint 2010 document library using JavaScript 使用REST更新SharePoint文档库中的文件内容-javascript - update a file content in SharePoint document library with REST - javascript Sharepoint:将程序复制文件复制到另一个文档库 - Sharepoint: Programmatic Copy File to Another Document library 在SharePoint网站中,将javascript文件应用于创建的每个文档库的选项是什么? - Within a SharePoint site, what is are my options to apply a javascript file to every document library that is created? Sharepoint:合并存储在“样式库”中的Javascript文件吗? - Sharepoint: Combining Javascript files stored in “Style Library”? 我需要将 HTML 生成为 PDF 并使用 Javascript 将 PDF 保存到 SharePoint 文档库 - I have requirement to generate HTML to PDF and save the PDF to SharePoint Document Library using Javascript 使用CSOM / JavaScript的SharePoint 2013 HTML5 Javascript上传到文档库 - SharePoint 2013 HTML5 Javascript Upload to Document library with CSOM/JavaScript 使用 HTML 中的超链接将文件上传到 SharePoint 2010 文档库时出现错误 - Bug while using a hyperlink from HTML to upload file to SharePoint 2010 document library
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM