Downloading Excel file xlsx in Angularjs and WebApi

后端 未结 5 794
离开以前
离开以前 2021-01-31 11:52


I am working on a task, in which I have to download a report in xlsx format. The report file is generated successfully from server, and is received on client side as well.

5条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-31 12:26

    I was facing the same error , content was in hexa format, so i added a response type as arraybuffer, problem got resolved. please see below.

    $http({
        url: '/api/sendPMOToBackendUpdate',
        method: "POST",
        headers: {'Content-type': 'application/json'},
        data: backendTsData,
        responseType: 'arraybuffer'
    }).success(function(data, status, headers){
        var file = new Blob([ data ], { type : 'application/vnd.ms-excel'});
        var defaultFileName ="TSC-"+$scope.user.name+"-"+$scope.user.ohrId+".xls";
        saveAs(file,defaultFileName);
    }).error(function(err) {
        console.log('Error: ' + err);
    });
    

提交回复
热议问题