1

I create an application with NDWS using sapui5 _javascript. I have a table in the view, which has some data (data is sync with database on server). I want to retrieve data from the table and export in into excel (so get separate excel doc). Here is my trigger:

var oExportToExcelButton = new sap.ui.commons.Button( {
            text : "Export to Excel",
            width : '120px',
            style : sap.ui.commons.ButtonStyle.Emph,
            press : function() {

                var jsonDataObject = oController.model.getProperty("/matreqs");
                var taskIdFromView = sap.ui.getCore().byId("taskId").getValue();
                var jsonData = JSON.stringify(jsonDataObject);

                $.ajax("api/wpi/processrequest/getexcelexportfile?taskId="
                    + taskIdFromView, {
                    context : this,
                    type : "POST",
                    processData : false,
                    contentType : "application/json",
                    data : jsonData,
                    error : function(request, status, error) {
                        console.log(error);
                    },
                    success : function(data) {
                        oController.getRequestParameterValue();
                        console.log(data);
                        top.close();
                    }
                });
            }
        });

getRequestParameterValue() is a function in controller:

getRequestParameterValue: function(name) {
        var half = location.search.split("&" + name + "=")[1];

        if (!half) half = location.search.split("?" + name + "=")[1];

        return half ? decodeURIComponent(half.split("&")[0]) : null;
    })

i am very new into programming, so i am sorry if my explanation is not very clear. any help is welcome!

4

1 回答 1

2

由于您已经可以oController.model .getProperty("/matreqs");在客户端访问按钮按下事件中的数据,因此您应该能够将数据发送到服务器端服务(例如 Java Servlet)。这应该关心将您的数据转换为有效的 Excel 文件。

您可以为此使用Apache POI。这对我来说很好。

如果您需要更多信息,请告诉我。

于 2014-01-17T13:33:14.183 回答