none
Push SharePoint Content To Excel Spread Sheet RRS feed

  • Question

  • I'm writing a code to get if versioning of documents in a SharePoint site is Enabled, or Disabled. I managed to get that working, but now I need to push the info to an excel file, the information that needs to be populated in it is the list name, the url to it and if versioning is enabled, or disabled. I use SP Services and for the excel part I'm using a JavaScript library I found on the net which is called Excel Plus. I tried different things, but none worked so far, it's returning an empty Excel file only with the names of the columns created, without any info being populated from the SharePoint page. What I'm trying to do is to have this function that is going throughout all SharePoint subsites, libraries, lists and then to get the list name, url and if versioning is enabled, or disabled of each document and push it to the created Excel columns. Here's the full code I've written so far, your help will be very much appreciated:

       var webAddress="SharePoint Site Goes Here";
       var liHtml = [];
       var fieldsStatic =[];
       var fieldsDisplay =[];
        $(document).ready(function() {          
            $().SPServices({
                operation: "GetAllSubWebCollection",
                webURL:webAddress,
                async: false,
                completefunc: function(xData, Status) {                    
                    $(xData.responseXML).SPFilterNode("Web").each(function(){
                        $('#outputDataDiv').append("<div class='webRecordTitle'>"
                        +$(this).attr("Title")+" : "
                        + $(this).attr("Url")+"</div>");
                        getListCollection($(this).attr("Url"));
                    });
                }
            });
    
        function getListCollection(webAddress){
             $().SPServices({
                operation: "GetListCollection",
                webURL:webAddress,
                async: false,
                completefunc: function(xData, Status) {
                    $(xData.responseXML).SPFilterNode("List").each(function(){
                        if(
                        $(this).attr("ServerTemplate")==101
                        && $(this).attr("Title")!=="Style Library"
                        && $(this).attr("Title")!=="Site Assets")
                        {
                        var outputListHtml = "<div class='listContainer'>"+
                        "<span class='listTitle'>"
                        +$(this).attr("Title")
                        + "</span><br />";
                        outputListHtml += "Total Item Count: "+$(this).attr("ItemCount")+" ";
                        outputListHtml +="</div>";
                        $('#outputDataDiv').append(outputListHtml);
                       }
                    });
                  }
               });
              } 
           })          
    
        function getList(webAddress, listName){
                $().SPServices({
                operation: "GetList",
                webURL: webAddress,
                listName: listName,
                async : false,
                completefunc: function(xData, Status) {
                    $(xData.responseXML).find("Fields > Field").each(function() {
                        fieldsStatic.push($(this).attr("StaticName"));
                        fieldsDisplay.push($(this).attr("DisplayName"));
                  })
                }
              });                        
            }
            getList(webAddress,"TestLibrary");       
    
        function getListItems(webAddress, listName){
                $().SPServices({
                operation: "GetListItems",
                webURL: webAddress,
                async: false,
                listName: listName,
                CAMLViewFields: "<ViewFields><FieldRef Name='Title' /></ViewFields>",
                completefunc: function (xData, Status) {
                    $(xData.responseXML).SPFilterNode("z:row").each(function() {
                        liHtml.push( "<li>" + $(this).attr("ows_Title") + "</li> ");
                        console.log(liHtml);
                    });
                  }
                })
            }
            getListItems(webAddress, "TestLibrary");
    
        var responseText = "" ;
        function getVersion(webAddress, listName){
                var result;
                $().SPServices({
                operation: "GetList",
                async: false,
                webURL: webAddress,
                listName: listName,
                completefunc: function (xData, Status) {
                var responseText = xData.responseText;
                if(responseText.indexOf('EnableVersioning="True"') > -1){
                        result = 'Enabled' ;
    
                }
                else {
                        result = 'Disabled'
                }
                }
            });
                return {listName: listName, webURL : webAddress, result: result };
        }
    
        function extractToExcel(sites){
                var ep=new ExcelPlus();
                var cellLetters=['A','B','C'];
                ep.createFile('Versioning');
                ep.write({'cell':'A1','content': 'List Name'});
                ep.write({'cell':'B1', 'content': 'URL'});
                ep.write({'cell':'C1', 'content': 'EnabledVersioning'});
                var array = [];
    
    
    
    
                ep.saveAs('Versioning.xlsx');
            };
    


    • Edited by terreror Thursday, February 9, 2017 1:45 PM
    Thursday, February 9, 2017 1:43 PM

All replies