cancel
Showing results for 
Search instead for 
Did you mean: 

how to download excel from local folder

former_member579519
Participant
0 Kudos

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

View Entire Topic
nicoschoenteich
Developer Advocate
Developer Advocate
0 Kudos

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

former_member579519
Participant
0 Kudos

Thank you so much @Nicolai Geburek for your replay

former_member579519
Participant
0 Kudos

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

nicoschoenteich
Developer Advocate
Developer Advocate
0 Kudos

Hi Srinivas,

Looks like the build tool doesn't like files that are not a simple text format. Which build tool are you using? Have you tried moving the excel files into the build result after the build and deploy that?

BR, Nico

former_member579519
Participant
0 Kudos

Thank you so much nicolai.geburek for your reply.

We are using the Business Application Studio with following commands.

1) npm run build

2) npm run deploy

nicoschoenteich
Developer Advocate
Developer Advocate
0 Kudos

Have you tried moving the files into the dist/ folder (your build result) manually?

former_member579519
Participant
0 Kudos

In dist/ folder build added files automatically. When I am deploying files are ignored.