Skip to Content
0

How to consume Excel URL fin sapui5

Nov 25, 2016 at 01:59 PM

77

avatar image

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)
10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

1 Answer

Best Answer
Jun Wu Nov 25, 2016 at 04:01 PM
0

remvoe your code and try this after get the fileurl

var encodeUrl=encodeURI(fileURL);

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

Show 1 Share
10 |10000 characters needed characters left characters exceeded

Hi Jun Wu,

Thanks for your answer. It's working fine.

Best Regards,

Viswanath

0