Question

I read this great help 'tool' from David Leedy regarding Export to excel.:

http://notesin9.com/wp-content/uploads/2011/01/XPagesCheatSheet-85x11-v1.pdf

My scenario: I have a ftsearch modulo which offers its results into a viewpanel. I want ONLY those results to be exported into excel. I follow the steps from the .pdf but in that case it will export all the documents listed in the respective view, not the search results.

Is there any possibility to have only the search results into the excel file, after the search is submited?

var myView:NotesView = database.getView('MyView');

Here I get the view which holds the search results, but I want to get the view contents/those docs. after the Search button was submitted. The problem is I don't get the 'updated' view only with the search results, but all the DOCS contained in that view. ( Before the Search button was clicked ... )

Thanks for your time!

Was it helpful?

Solution

You say that you already have a view panel that shows the search results. I'm assuming that you're using the search attribute on the view panel object to do that. Another assumption is that you're computing the full text query in the search attribute based on an input field that's bound to a scoped variable (possibly the sessionScope). So your datasource on the search XPage would look something like this:

<xp:this.data>
  <xp:dominoView
    var="view1"
    viewName="yourSearchView">
    <xp:this.search><![CDATA[#{javascript:"[subject]=\"" + sessionScope.searchField + "*\"";}]]></xp:this.search>
  </xp:dominoView>
</xp:this.data>

In the Export XPage you can restrict the entries that are exported by applying the same query to the view before exporting the results. To do that you can use the 'FTSearch()' function on the view:

myView.FTSearch("[subject]=\"" + sessionScope.searchField + "*\");

Based on the code on David's cheatsheet I tested this and it turns out that for some reasons if you add this row, the NotesViewNavigator that is constructed based on the (filtered) view isn't limited to the search results, but still contains all entries. The solution to that is to remove the NotesViewNavigator object and use a NotesViewEntryCollection:

var exCon = facesContext.getExternalContext(); 
var writer = facesContext.getResponseWriter();
var response = exCon.getResponse();

var myView:NotesView = database.getView('vwKlanten');
var query = "[subject]=\"em*\"";
myView.FTSearch(query);

var vec:NotesViewEntryCollection = myView.getAllEntries()

var viewEnt:NotesViewEntry = vec.getFirstEntry();

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("</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("</tr>");

 var tmp = vec.getNextEntry(viewEnt);
 viewEnt.recycle();
 viewEnt = tmp;
}

writer.write("</table>");
writer.endDocument();

(BTW: I added a 'recycle()' call to deal with possible memory errors)

OTHER TIPS

Have You already tried http://poi4xpages.openntf.org/ ? A custom control for exporting data to excel or word

For me, rather then trying to get ahold of the search results from the code that produces the report, I'd just have that code run the same search again. At least to get it working. Then I'd deal with trying to cut it back to 1 search call. You might find that running 2 searches just isn't a big deal.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top