title: Angular - SheetJS - How to export HTML Table to Excel?
body: <p>I copied the code from this "tutorial":</p>
  
  <p><a href="https://sheetjs.com/demos/table.html" rel="noreferrer">https://sheetjs.com/demos/table.html</a></p>
  
  <pre><code>function doit(type, fn, dl) {
     var elt = document.getElementById('data-table');
     var wb = XLSX.utils.table_to_book(elt, {sheet:"Sheet JS"});
     return dl ?
      XLSX.write(wb, {bookType:type, bookSST:true, type: 'base64'}) :
      XLSX.writeFile(wb, fn || ('test.' + (type || 'xlsx')));
  }
  </code></pre>
  
  <p>So I ended up creating this method in Angular:</p>
  
  <pre><code>exportTableToExcel() {
     var type = "xlsx"
     var elt = document.getElementsByClassName('table');
     var wb = XLSX.utils.table_to_book(elt, /*{sheet:"Sheet JS"}*/);
     return XLSX.writeFile(wb, undefined || ('test.' + (type || 'xlsx')));
  }
  </code></pre>
  
  <p>Well, on the line of the table_to_book method, I receive this exception:</p>
  
  <blockquote>
    <p>table.getElementsByTagName is not a function</p>
  </blockquote>
  
  <p>I also tried this tutorial, which is similar, but it's for Angular 4, not 5.</p>
  
  <p><a href="http://vinhboy.com/blog/2017/06/13/how-to-use-sheetjs-xlsx-with-angular-4-typescript-in-the-browser/" rel="noreferrer">http://vinhboy.com/blog/2017/06/13/how-to-use-sheetjs-xlsx-with-angular-4-typescript-in-the-browser/</a></p>