export data from panel

99封情书 提交于 2019-11-29 17:28:08

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)

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!