Enter this code in Xpage - after Render Response...
var exCon = facesContext.getExternalContext();
var writer = facesContext.getResponseWriter();
var response = exCon.getResponse();
var projects:NotesView = database.getView("vwFirst") //view name
var viewNav:NotesViewNavigator = projects.createViewNav();
var viewEnt:NotesViewEntry = viewNav.getFirst();
var output = "";
var i=0;
while (viewEnt != null) {
output += "<tr>";
output += "<td>" + viewEnt.getColumnValues()[0] + "</td>";
output += "<td>" + viewEnt.getColumnValues()[1] + "</td>"; //viewEnt.getColumnValues()
output += "<td>" + viewEnt.getColumnValues()[2] + "</td>";
output += "<td>" + viewEnt.getColumnValues()[3] + "</td>";
output += "<td>" + viewEnt.getColumnValues()[4] + "</td>";
output += "</tr>";
i=i+1;
viewEnt = viewNav.getNext(viewEnt);
}
response.setContentType("application/csv-tab-delimited-table;charset=utf-8");
response.setHeader("Cache-Control", "no-cache");
response.setHeader("Content-Disposition","attachment; filename=\"export.xls\"");
writer.write("<html>");
writer.write("<head>");
writer.write("<meta http-equiv=\"Content-Type\" content=\"text/html;charset=utf-8\"/>")
writer.write("</head>");
writer.write("<body>");
writer.write("<table>");
writer.write("<tr>");
for(var t=0;t<projects.getColumnNames().length;t++)
{
writer.write("<td><b>"+projects.getColumnNames()[t]+"</b></td>");
}
//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>");
writer.write(output);
writer.write("</table>");
writer.write("<body>");
writer.write("</html>");
writer.endDocument();
No comments:
Post a Comment