Monday, 25 July 2022

sending string from C# to client and converting into Uint8Array type byte array and then into blob to open excel file. Corgi Involved

So here in C# code i am sending corgi to client which has corgiBabies

   corgi.Corgibabies = System.Text.Encoding.UTF8.GetString(Corgibabies);
        
     return corgi;

After that in Client i want to open corgibabies in excel sheet but the conversion here is wrong somewhere i think that excel sheet doesn't open correctly.

var fileName = 'CorgiBabies.xlsx';

     dataAccessService.get('corgi')
            .then(function(response) {
                let utf8Encode = new TextEncoder();
                var strBytes = utf8Encode.encode(response.corgiBabies);
            
                    var a = document.createElement("a");
                    document.body.appendChild(a);
                    a.style = "display: none";
                    
                    var file = new Blob([strBytes], {type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'});
                    var fileURL = window.URL.createObjectURL(file);
                    a.href = fileURL;
                    a.download = fileName;
                    a.click();
                
            })

Below what excel sheet gives me error in image

enter image description here



from sending string from C# to client and converting into Uint8Array type byte array and then into blob to open excel file. Corgi Involved

No comments:

Post a Comment