Hide Export to Excel Button from List Ribbon Using JavaScript in SharePoint 2013

Sometimes you create List/Document Library using Visual Studio and you need to hide ‘Export to Excel’ button from Ribbon. You do not want to do it using SharePoint Designer because you have to do it manually in all the environments. Using this JavaScript approach you can hide this button from Ribbon.

Implementation:
We are going to customize the List View using JavaScript.

1. Add a JavaScript file (HideExportToExcel.js) in your solution.

2. Modify schema.xml of the List and add the reference of JavaScript file to the <JSLink> tag.
 
Add below code to the JavaScript file.   
  1. var nIntervId;  
  2.   
  3. // DOM is ready  
  4. (function () {  
  5.     var e = ExecuteOrDelayUntilScriptLoaded(  
  6.             CallHide,  
  7.             "sp.js");  
  8. })();  
  9.   
  10. //Call this function on click of 'LIST' until Export to Excel link is hidden  
  11. function CallHide() {  
  12.     document.addEventListener('click'function (evt) {  
  13.         if (evt.target.textContent == "List") {  
  14.             nIntervId = setInterval(HideExportLink, 50);  
  15.         }  
  16.     });  
  17. }  
  18.   
  19. //Hide 'Export to Excel' Span if it is rendered in the Ribbon Menu  
  20. function HideExportLink() {      
  21.     //Get Span which contains the Export Link  
  22.     var exportSpan = document.getElementById('Ribbon.List.Actions-LargeMedium-0-0');  
  23.     if (exportSpan != null) {  
  24.         // set the display to none  
  25.         exportSpan.style.display = 'none';  
  26.         //Since link is hidden, Stop CallHide()  
  27.         StopCallHide();  
  28.     }  
  29. }  
  30.   
  31. //Clear Interval  
  32. function StopCallHide() {      
  33.     clearInterval(nIntervId);  
  34. }  

· Open schema.xml of ‘TestList’ and go to the AllItems View tag <View BaseViewID="1"……………>. Update the <JSLink>tag to reference this JavaScript.

  1. <!-- Hide Export to Excel-->  
  2. <JSLink>~site/Scripts/HideExportToExcel.js</JSLink>