on 08-25-2022 2:19 PM
Hi Experts,
My client provided an excel file when I click a download button excel file should download. I have created a folder and uploaded the file locally.
onPressDownload:function(Event){
// var sPath = sap.ui.require.toUrl("com/sap/abc/PromotionCockpit/excel/Mass_upload.xlsx");
var sPath = jQuery.sap.getModulePath("com.sap.abc.PromotionCockpit") + "/excel/Mass_upload.xlsx";
}<br>
Please help me. Thanks in advance.
Thanks & Regards
Srinivas Raju
Hi Srinivas,
This is actually very simple:
onPressDownload: function () {
const oA = document.createElement("a");
oA.href = "/excel/Mass_upload.xlsx";
oA.style.display = "none";
document.body.appendChild(oA);
oA.click();
document.body.removeChild(oA);
}
See this blog post for more info: https://blogs.sap.com/2018/09/16/six-and-three-half-ways-to-start-a-download-in-sapui5-and-maybe-a-f...
You should be careful with the name of your excel file, I believe it contains a space character.
BR, Nico
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi nicolai.geburek
By using your code excel file is downloading it was working fine in locally In my BAS. When I am trying to deploy my application excel file is not uploaded. I have attached a screenshot below.
:-Webapp
:-While deploying (file is not uploaded)
I have changed the file to a .txt file
onPressDownload: function (Event) {
var oBundle = this.getView().getModel("i18n").getResourceBundle();
if(sap.ui.getCore().getConfiguration().getLanguage()=== "de"){
var sPath = sap.ui.require.toUrl("com/sap/aldi/ZPromotionCockpit/excel/Create_Promotion_De.txt");
}else{
var sPath = sap.ui.require.toUrl("com/sap/aldi/ZPromotionCockpit/excel/Create_Promotion_En.txt");
}
const oA = document.createElement("a");
oA.href = sPath;
oA.style.display = "none";
oA.download = (oBundle.getText("lblPromotioncreation") + ".xlsx").replace(/\s/g, '');
document.body.appendChild(oA);
oA.click();
document.body.removeChild(oA);
},
:- After redeploying
Please help me. Thanks in advance.
Thanks & Regards
Srinivas Raju
User | Count |
---|---|
69 | |
8 | |
8 | |
6 | |
6 | |
6 | |
5 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.