将视图日期范围导出到 excel

export view daterange to excel

我正在尝试将视图日期范围导出到 excel,但 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 不为空。

您正在尝试获取基于范围的条目,而不是获取范围内的所有条目。尝试:

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