1

I'd like to download a Excel per REST call. If I use Postman to test the endpoint it works fine. But if I start the request on my website the respons is ok but I have no idea how i can change de response to a Excelfile download.

Here is my code:

  async export () {
  const data = await generateExport()
  const blob = new Blob([data], {
    type:
      'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
  })
  require('downloadjs')(
    blob,
    'FileName_' +
      new Date().toLocaleDateString() +
      '.xlsx',
    'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
  )
}

OR

    async export () {
  var data = await generateExport()
  require('downloadjs')(
    data,
    'FileName_' +
      new Date().toLocaleDateString() +
      '.xlsx',
    'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
  )
}

Thank you for your answer Best wishes

Simon
  • 96
  • 1
  • 9
  • https://stackoverflow.com/questions/3749231/download-file-using-javascript-jquery – ndpu Mar 02 '18 at 13:11
  • You can use this library if your REST call returns data in JSON format - https://www.npmjs.com/package/vue-json-excel – ni8mr Jul 24 '18 at 06:12

1 Answers1

1

Now I used downloadjs as ES6. After a while, I saw, that the server response was not only the file. It was in a container which also was named data. Now I simply navigated in the object to the source.

import * as download from 'downloadjs'

...

var data = await generateExport();

download(
    data.data,
    'NameOfTheFile_' + new Date().toLocaleDateString() + '.xlsx',
    'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml'
  )
Simon
  • 96
  • 1
  • 9