Skip to Content
avatar image
Former Member

How to consume Excel URL fin sapui5

Hi Everyone,

I have requirement, where from backend they are providing Excel link on click of button in UI I should consume that URL and download that Excel.

I wrote below code on click of Button. I am taking URL into fileURL variable but I am unable to download .

var oModel = new sap.ui.model.odata.ODataModel(CONSTANTS.BUPA_ODATA,true); 
var sRead = "/DownloadSet" ; 
oModel.read( sRead, null, null, true, function(oData, oResponse){ 
 console.log(oData); var fileURL = oData.results[0].url; 
 var link = document.createElement("a"); 
link.href =  fileURL ; 
 link.style = "visibility:hidden"; 
link.download = fileURL ; //this part will append the anchor tag and remove it after automatic click document.body.appendChild(link); 
link.click(); document.body.removeChild(link);
},
function(){ alert("Read failed"); }); 

It's Downloading Excel with No file.

My Odata service looks as attached and in that Property URL having Excel link.

Could anyone please help how to get that exact URL and download excel in SAPUI5.

Gatewayserver giving Excel

Thanks,

Best Regards,

Viswanath

noexcel.png (2.1 kB)
service.png (83.5 kB)
excel.png (81.0 kB)
Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • Best Answer
    Nov 25, 2016 at 04:01 PM

    remvoe your code and try this after get the fileurl

    var encodeUrl=encodeURI(fileURL);

    sap.m.URLHelper.redirect(encodeUrl,true);

    Add comment
    10|10000 characters needed characters exceeded