I want to save a search report into an excel file but it is saving with the .xsp extension not excel.
I use the following code:
<?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>
I use this code from a pdf... It is not my own creation, maybe something is wrong.
Thanks,
Florin
Add a line
response.setHeader("Content-Disposition", "attachment; filename=yourfile.xls");
or
response.setHeader("Content-Disposition", "inline; filename=yourfile.xls");
With "inline", the browser will try to open the file within the browser, whereas "attachment" will force it to download.
What is wrong with this?
var exCon = facesContext.getExternalContext();
var writer = facesContext.getResponseWriter();
var response = exCon.getResponse();
var myView:NotesView = database.getView('vwSearch');
myView.FTSearch("sessionScope.search");
var viewNav:NotesViewNavigator = myView.createViewNav();
var viewEnt:NotesViewEntry = viewNav.getFirst();
response.setContentType("application/vnd.ms-excel");
response.setHeader("Cache-Control", "no-cache");
response.setHeader("Content-Disposition", "attachment; filename=raport.xls");
writer.write("<table>");
writer.write("<thead><tr>");
writer.write("<td><b>Nume</b></td>");
writer.write("<td><b>Ora Intrare</b></td>");
writer.write("<td><b>Ora Iesire</b></td>");
writer.write("<td><b>Timp</b></td>");
writer.write("<td><b>Timp 2</b></td>");
writer.write("<td><b>Data Creare</b></td>");
writer.write("<td><b>Email</b></td>");
writer.write("<td><b>Telefon</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].toJavaDate().getHours()+":"+viewEnt.getColumnValues()[1].toJavaDate().getMinutes() + "</td>");
writer.write("<td>" + viewEnt.getColumnValues()[2].toJavaDate().getHours()+":"+viewEnt.getColumnValues()[2].toJavaDate().getMinutes() + "</td>");
writer.write("<td>" + viewEnt.getColumnValues()[3] + "</td>");
writer.write("<td>" + "08:00" + "</td>");
writer.write("<td>" + viewEnt.getColumnValues()[4].toJavaDate() + "</td>");
writer.write("<td>" + viewEnt.getColumnValues()[5] + "</td>");
writer.write("<td>" + viewEnt.getColumnValues()[6] + "</td>");
writer.write("</tr>");
viewEnt = viewNav.getNext(viewEnt);
}
writer.write("</table>");
writer.endDocument()
Even if I use: myView.FTSearch("Jeff"); it will not show only documents with Jeff... Why?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With