The following is the code which is used to export the selected documents to excel in Xpages
var exCon = facesContext.getExternalContext();
var writer = facesContext.getResponseWriter();
var response = exCon.getResponse();
var projects:NotesView = database.getView(’EmployeeList’)
var viewNav:NotesViewNavigator = projects.createViewNav();
var viewEnt:NotesViewEntry = viewNav.getFirst();
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 += “</tr>”;
viewEnt = viewNav.getNext(viewEnt);
}
response.setContentType(”application/vnd.ms-excel”);
response.setHeader(”Cache-Control”, “no-cache”);
response.setHeader(”Content-Disposition”,”attachment;filename=EmployeeDetails.xls”) ;
writer.write(”<table>”);
writer.write(”<thead><tr>”);
writer.write(”<td><b>EmployeeName</b></td>”);
writer.write(”<td><b>EmployeeId</b></td>”);
writer.write(”<td><b>Department</b></td>”);
writer.write(”<td><b>Designation</b></td>”);
writer.write(”</tr></thead>”);
writer.write(output);
writer.write(”</table>”);
writer.endDocument();
var exCon = facesContext.getExternalContext();
var writer = facesContext.getResponseWriter();
var response = exCon.getResponse();
var projects:NotesView = database.getView(’EmployeeList’)//view name
var viewNav:NotesViewNavigator = projects.createViewNav();
var viewEnt:NotesViewEntry = viewNav.getFirst();
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 += “</tr>”;
viewEnt = viewNav.getNext(viewEnt);
}
response.setContentType(”application/vnd.ms-excel”);
response.setHeader(”Cache-Control”, “no-cache”);
response.setHeader(”Content-Disposition”,”attachment;filename=EmployeeDetails.xls”) ;
writer.write(”<table>”);
writer.write(”<thead><tr>”);
writer.write(”<td><b>ColumnName1</b></td>”);
writer.write(”<td><b>ColumnName2</b></td>”);
writer.write(”<td><b>ColumnName3</b></td>”);
writer.write(”<td><b>ColumnName4</b></td>”);
writer.write(”</tr></thead>”);
writer.write(output);
writer.write(”</table>”);
writer.endDocument();
No comments:
Post a Comment