title: Export excel file using exceljs to client
body: <p>I'm trying to export excel file using exceljs library. I'm using AngularJS and NodeJS.</p>
  
  <p>Here is my code:</p>
  
  <p>HTML:</p>
  
  <pre><code>&lt;a class="btn m-b-xs btn-info btn-doc" ng-click="exportExcel()" style='background-color: #34495e; margin-left: 5%;'&gt;
  &lt;/a&gt;
  </code></pre>
  
  <p>Controller:</p>
  
  <pre><code>$scope.exportExcel = function() {
      $http.post('/api/exportExcel/exportExcel', {"data": $scope.data});
  };
  </code></pre>
  
  <p>NodeJS:</p>
  
  <pre><code>const Excel = require('exceljs');
  
  export async function exportExcel(req, res) {
      try {
      var workbook = new Excel.Workbook();
      var worksheet = workbook.addWorksheet('My Sheet');
  
      worksheet.columns = [
          { header: 'Id', key: 'id', width: 10 },
          { header: 'Name', key: 'name', width: 32 },
          { header: 'D.O.B.', key: 'DOB', width: 10 }
      ];
      worksheet.addRow({id: 1, name: 'John Doe', dob: new Date(1970,1,1)});
      worksheet.addRow({id: 2, name: 'Jane Doe', dob: new Date(1965,1,7)});
  
      var tempFilePath = tempfile('.xlsx');
      workbook.xlsx.writeFile(tempFilePath).then(function() {
          console.log('file is written');
          res.sendFile(tempFilePath, function(err){
              console.log('---------- error downloading file: ' + err);
          });
      });
  } catch(err) {
      console.log('OOOOOOO this is the error: ' + err);
  }
  }
  </code></pre>
  
  <p>I've just found this example of code for generating excel just to try get excel file on client side and after that i will create my own file.
  But for now i just get in log this error </p>
  
  <pre><code>file is written
  (node:25624) UnhandledPromiseRejectionWarning: TypeError: res.sendFile is not a function
  </code></pre>
  
  <p>Does anyone can help me to get excel file in browser after i click on button for export?</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>controller:</p>
  
  <pre><code>$scope.exportExcel = function() {
              $http.post('/api/exportExcel/exportExcel', {"offer": $scope.offer})
              .then(function(response) {
                  console.log(response.data);
                  var data = response.data,
                  blob = new Blob([data], { type: response.headers('content-type') }),
                  url = $window.URL || $window.webkitURL;
                  $scope.fileUrl = url.createObjectURL(blob);
              });
          };
  </code></pre>
  
  <p>html:</p>
  
  <pre><code>&lt;a class="btn m-b-xs btn-info btn-doc" ng-click="exportExcel()" ng-href="{{ fileUrl }}" download="table.xlsx"&gt;
  &lt;i class="fa"&gt;&lt;/i&gt;Export&lt;/a&gt;
  </code></pre>