简体   繁体   中英

How can I download an excel file in angular 6

How do I download excel file at an angular 6

The file sent to my angular from C# as an array of bytes by webApi

The required format is .xlsx

 downloadFile(result, fileName) {
    var byteArray = new Uint8Array(atob(result).split('').map(char => char.charCodeAt(0)));
    var blb = new Blob([byteArray], { type: EXCEL_TYPE });
    FileSaver.saveAs(blb, fileName);
  }

(resulat = c# byte array)

Try File Saver. That's what I use.

npm install file-saver --save
npm install @types/file-saver --save

This post may help you:

How do I download a file with Angular2 or greater

Cheers.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM