Skip to main content link. Accesskey S

The useful resource for IBM Lotus Domino XPages development

Submit Search

Available in the Appstore!All the content of xpageswiki.com for iPhone or iPad for offline access.

Home > How to export to Excel or other formats

How to export to Excel or other formats

ShowTable of Contents
HideTable of Contents

Basic export


You can write data directly to the browser and tell him to download the data instead of displaying it.
Here an example with an CSV-file:

var exCon = facesContext.getExternalContext(); 
var writer = facesContext.getResponseWriter();
var response = exCon.getResponse();
response.setContentType("application/csv-tab-delimited-table;charset=utf-8");
response.setHeader("Cache-Control", "no-cache");
response.setHeader("Content-Disposition","attachment; filename="export.csv"");
var s = "name;lastname;officestreetaddress";
writer.write(s);
writer.endDocument();

Export to Excel


You can export data as a table in a HTML file and tell the browser to open it with Excel, simply by faking a filename with ".xsl" extension instead of ".html":

var exCon = facesContext.getExternalContext(); 
var writer = facesContext.getResponseWriter();
var response = exCon.getResponse();
response.setContentType("application/csv-tab-delimited-table;charset=utf-8");
response.setHeader("Cache-Control", "no-cache");
response.setHeader("Content-Disposition","attachment; filename="export.xsl"");
s = "<html><head><meta http-equiv="Content-Type" content="text/html;charset=utf-8"/></head><body>";
var s = "<table>";
s += "<tr><td>name</td><td>lastname</td><td>officestreetaddress</td></tr>";
s += "</table>";
s += "</body></html>";
writer.write(s);
writer.endDocument();

Created by lazy on Jan 10, 2012 9:54:36 AM

hello,does it work when content contans chinese? I test it with the chinese ,it returns unreadable code,what's the reason


Add Comment

Name:
Comments:
Use  searchlotus.com  for news in the Web related to Lotus Notes and Domino,
and to search those sites.
Check  youatnotes.com  for great Lotus Notes, Domino and XPages software.
Did this information help you?
Please honor our efforts and flattr this!