title: Exclude column when Exporting table in javascript
body: <p>Is there any way how can I exclude specific columns when exporting table to excel file, I just want to exclude Firstname and Savings to excel file. Currently I just only export all of my data from my tables but I want to exclude Firstname and Savings column, Is there any expert can help?
  <a href="https://i.stack.imgur.com/fF4Lk.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/fF4Lk.png" alt="enter image description here" /></a></p>
  <blockquote>
  <p>html</p>
  </blockquote>
  <pre><code>&lt;button id='btnExport'&gt;
  Export To Excel
  &lt;/button&gt;
  &lt;table id='testExportId'&gt;
    &lt;tr&gt;
      &lt;th &gt;Firstname&lt;/th&gt;
      &lt;th &gt;Lastname&lt;/th&gt;
      &lt;th &gt;Savings&lt;/th&gt;
      &lt;th &gt;wowww&lt;/th&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Peter&lt;/td&gt;
      &lt;td&gt;Griffin&lt;/td&gt;
      &lt;td&gt;$100&lt;/td&gt;
      &lt;td&gt;$100&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Lois&lt;/td&gt;
      &lt;td&gt;Griffin&lt;/td&gt;
      &lt;td&gt;$150&lt;/td&gt;
      &lt;td&gt;$100&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Joe&lt;/td&gt;
      &lt;td&gt;Swanson&lt;/td&gt;
      &lt;td&gt;$300&lt;/td&gt;
      &lt;td&gt;$100&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Cleveland&lt;/td&gt;
      &lt;td&gt;Brown&lt;/td&gt;
      &lt;td&gt;$250&lt;/td&gt;
      &lt;td&gt;$100&lt;/td&gt;
  &lt;/tr&gt;
  &lt;/table&gt;
  </code></pre>
  <blockquote>
  <p>javascript</p>
  </blockquote>
  <pre><code>&lt;script src = &quot;https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js&quot;&gt;&lt;/script&gt;
  &lt;script type=&quot;text/javascript&quot;&gt;
      
  $(document).ready(function(){
  $(&quot;#btnExport&quot;).click(
              function () {
                  tableToExcel('testExportId','test','trys');
              }            
          );
  })
  function getIEVersion()
  // Returns the version of Windows Internet Explorer or a -1
  // (indicating the use of another browser).
  {
      var rv = -1; // Return value assumes failure.
      if (navigator.appName == 'Microsoft Internet Explorer') {
          var ua = navigator.userAgent;
          var re = new RegExp(&quot;MSIE ([0-9]{1,}[\.0-9]{0,})&quot;);
          if (re.exec(ua) != null)
              rv = parseFloat(RegExp.$1);
      }
      return rv;
  }
  function tableToExcel(table, sheetName, fileName) {
      
      var ua = window.navigator.userAgent;
      var msie = ua.indexOf(&quot;MSIE &quot;);
      if (msie &gt; 0 || !!navigator.userAgent.match(/Trident.*rv\:11\./))      // If Internet Explorer
      {
          return fnExcelReport(table, fileName);
      }
  
      var uri = 'data:application/vnd.ms-excel;base64,',
          templateData = '&lt;html xmlns:o=&quot;urn:schemas-microsoft-com:office:office&quot; xmlns:x=&quot;urn:schemas-microsoft-com:office:excel&quot; xmlns=&quot;http://www.w3.org/TR/REC-html40&quot;&gt;&lt;head&gt;&lt;!--[if gte mso 9]&gt;&lt;xml&gt;&lt;x:ExcelWorkbook&gt;&lt;x:ExcelWorksheets&gt;&lt;x:ExcelWorksheet&gt;&lt;x:Name&gt;{worksheet}&lt;/x:Name&gt;&lt;x:WorksheetOptions&gt;&lt;x:DisplayGridlines/&gt;&lt;/x:WorksheetOptions&gt;&lt;/x:ExcelWorksheet&gt;&lt;/x:ExcelWorksheets&gt;&lt;/x:ExcelWorkbook&gt;&lt;/xml&gt;&lt;![endif]--&gt;&lt;meta http-equiv=&quot;content-type&quot; content=&quot;text/plain; charset=UTF-8&quot;/&gt;&lt;/head&gt;&lt;body&gt;&lt;table&gt;{table}&lt;/table&gt;&lt;/body&gt;&lt;/html&gt;',
          base64Conversion = function (s) { return window.btoa(unescape(encodeURIComponent(s))) },
          formatExcelData = function (s, c) { return s.replace(/{(\w+)}/g, function (m, p) { return c[p]; }) }
  
      $(&quot;tbody &gt; tr[data-level='0']&quot;).show();
  
      if (!table.nodeType)
          table = document.getElementById(table)
  
      var ctx = { worksheet: sheetName || 'Worksheet', table: table.innerHTML }
  
      var element = document.createElement('a');
      element.setAttribute('href', 'data:application/vnd.ms-excel;base64,' + 
      base64Conversion(formatExcelData(templateData, ctx)));
      element.setAttribute('download', fileName);
      element.style.display = 'none';
      document.body.appendChild(element);
      element.click();
      document.body.removeChild(element);
  
      $(&quot;tbody &gt; tr[data-level='0']&quot;).hide();
  }
  
  function fnExcelReport(table, fileName) {
      
      var tab_text = &quot;&lt;table border='2px'&gt;&quot;;
      var textRange;
  
      if (!table.nodeType)
          table = document.getElementById(table)
  
      $(&quot;tbody &gt; tr[data-level='0']&quot;).show();
      tab_text =  tab_text + table.innerHTML;
  
      tab_text = tab_text + &quot;&lt;/table&gt;&quot;;
      tab_text = tab_text.replace(/&lt;A[^&gt;]*&gt;|&lt;\/A&gt;/g, &quot;&quot;);//remove if u want links in your table
      tab_text = tab_text.replace(/&lt;img[^&gt;]*&gt;/gi, &quot;&quot;); // remove if u want images in your table
      tab_text = tab_text.replace(/&lt;input[^&gt;]*&gt;|&lt;\/input&gt;/gi, &quot;&quot;); // reomves input params
  
      txtArea1.document.open(&quot;txt/html&quot;, &quot;replace&quot;);
      txtArea1.document.write(tab_text);
      txtArea1.document.close();
      txtArea1.focus();
      sa = txtArea1.document.execCommand(&quot;SaveAs&quot;, false, fileName + &quot;.xls&quot;);
      $(&quot;tbody &gt; tr[data-level='0']&quot;).hide();
      return (sa);
  }
  
  
  &lt;/script&gt;
  </code></pre>