gpt4 book ai didi

excel - Xpages,将 View 保存到 Excel 文件中

转载 作者:行者123 更新时间:2023-12-02 09:58:24 25 4
gpt4 key购买 nike

我想将搜索报告保存到 Excel 文件中,但它是以 .xsp 扩展名保存的,而不是 Excel。

我使用以下代码:

<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core" rendered="false">
<xp:this.afterRenderResponse><![CDATA[#{javascript:
var exCon = facesContext.getExternalContext();
var writer = facesContext.getResponseWriter();
var response = exCon.getResponse();
var myView:NotesView = database.getView('vwSearch');
var viewNav:NotesViewNavigator = myView.createViewNav();
var viewEnt:NotesViewEntry = viewNav.getFirst();
print("2")
response.setContentType("application/vnd.ms-excel");
response.setHeader("Cache-Control", "no-cache");
writer.write("<table>");
writer.write("<thead><tr>");
writer.write("<td><b>Column1Header</b></td>");
writer.write("<td><b>Column2Header</b></td>");
writer.write("<td><b>Column3Header</b></td>");
writer.write("<td><b>Column4Header</b></td>");
writer.write("<td><b>Column5Header</b></td>");
writer.write("</tr></thead>");
while (viewEnt != null) {
writer.write("<tr>");
writer.write("<td>" + viewEnt.getColumnValues()[0] + "</td>");
writer.write("<td>" + viewEnt.getColumnValues()[1] + "</td>");
writer.write("<td>" + viewEnt.getColumnValues()[2] + "</td>");
writer.write("<td>" + viewEnt.getColumnValues()[3] + "</td>");
writer.write("<td>" + viewEnt.getColumnValues()[4] + "</td>");
writer.write("</tr>");
viewEnt = viewNav.getNext(viewEnt);
}
writer.write("</table>");
writer.endDocument()}]]></xp:this.afterRenderResponse>
</xp:view>

我使用 pdf 中的代码...这不是我自己的创作,也许有问题。

谢谢

弗罗林

最佳答案

添加一行

response.setHeader("Content-Disposition", "attachment; filename=yourfile.xls");

response.setHeader("Content-Disposition", "inline; filename=yourfile.xls");

使用“内联”,浏览器将尝试在浏览器中打开文件,而“附件”将强制下载文件。

关于excel - Xpages,将 View 保存到 Excel 文件中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25479458/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com