downloading xlsx file in angular 2 with blob

前端 未结 6 758
悲&欢浪女
悲&欢浪女 2021-01-02 02:31

I want to download xlsx file from the client on angular 2 using rest api.

I\'m getting a byte array as a response from my GET request and I\'m sending it to download

6条回答
  •  盖世英雄少女心
    2021-01-02 03:14

    After nothing works. I changed my server to return the same byte array with the addition of:

        response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
        response.setHeader("Content-Disposition", "attachment; filename=deployment-definitions.xlsx");
    

    At my client I deleted the download function and instead of the GET part i did:

    window.open(this.restUrl, "_blank");
    

    This is the only way I found it possible to save an xlsx file that is not corrupted.

    If you have a answer about how to do it with blob please tell me :)

提交回复
热议问题