如何使用ajax调用+ javascript将数据从数据库导出到excel中

我使用sapui5 _javascript创build了一个NDWS应用程序。 我有一个表中的视图,其中有一些数据(数据与服务器上的数据库同步)。 我想从表中检索数据并导入到Excel中(所以得到单独的Excel文档)。 这是我的触发器:

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()是控制器中的一个函数:

 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; }) 

如果我的解释不是很清楚的话,我很抱歉。 任何帮助,欢迎!

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

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

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