我使用 sapui5 _javascript 创建了一个带有 NDWS 的应用程序。我在 View 中有一个表,其中有一些数据(数据与服务器上的数据库同步)。我想从表中检索数据并导出到 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() 是 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;
})
我是编程新手,所以如果我的解释不是很清楚,我很抱歉。欢迎任何帮助!
最佳答案
因为您已经可以使用 oController.model 访问按钮按下事件中的数据
.getProperty("/matreqs");
在客户端,您应该能够将数据发送到服务器端服务(例如 Java Servlet)。这应该关心将您的数据转换为有效的 Excel 文件。
您可以使用 Apache POI为了这。这对我来说很好。
如果您需要更多信息,请告诉我。
关于javascript - 如何使用ajax调用+ javascript将数据从数据库导出到excel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21185593/