导出视图daterange到excel

时间:2015-02-03 11:06:25

标签: xpages xpages-ssjs

我尝试将视图日期范围导出为ex​​cel,但似乎notesviewentry始终为空。 我的代码:

var vDateRange = session.createDateRange(sessionScope.selectedStartDate, sessionScope.selectedEndDate);
var exCon = facesContext.getExternalContext();
var writer = facesContext.getResponseWriter();
var response = exCon.getResponse();
var projects:NotesView = database.getView('visits_by_date_VB')
var viewNav:NotesViewNavigator = projects.createViewNav();
var viewEnt:NotesViewEntry = viewNav.getEntryByKey([vDateRange]);
var output:string = "";
while (viewEnt != null) {
 output += "<tr>";
 output += "<td>" + viewEnt.getColumnValues()[0]; + "</td>";
 output += "<td>" + viewEnt.getColumnValues()[1] + "</td>";
 output += "<td>" + viewEnt.getColumnValues()[2] + "</td>";
 output += "<td>" + viewEnt.getColumnValues()[3] + "</td>";
 output += "<td>" + viewEnt.getColumnValues()[4] + "</td>";
 output += "</tr>";
viewEnt = viewNav.getNext(viewEnt);
}
response.setContentType("application/vnd.ms-excel");
response.setHeader("Cache-Control", "no-cache");
response.setHeader("Content-Disposition","attachment; filename=export.xls");
writer.write("<table>");
writer.write("<thead><tr>");
writer.write("<td><b>Branch Id</b></td>");
writer.write("<td><b>Company Name</b></td>");
writer.write("<td><b>Share value</b></td>");
writer.write("<td><b>City</b></td>");
writer.write("<td><b>Country</b></td>");
writer.write("</tr></thead>");
writer.write(output);
writer.write("</table>");
writer.endDocument();

sessionScope不是空的。

1 个答案:

答案 0 :(得分:2)

您正在尝试根据范围获取条目,而不是获取范围之间的所有条目。尝试:

var viewEntryCollection:NotesViewEntryCollection = projects.getAllEntriesByKey([vDateRange]);
var viewEnt:NotesViewEntry = viewEntryCollection.getFirstEntry();