Armin Mandel
Armin Mandel

Reputation: 117

Export Lotus Notes rich-text mime content into Word/Excel via Apache-POI

I created a webpage and want to allow the users to export the content of the pages. For that I used the Apache-POI libs. That works fine for text. But how can I export mime content? If I change the rich-text properties to 'Store content as html/mime' (because I want to format the content in Notes and sometimes the content contains an image). If that is not possible what are useable alternatives in a xpage?

The code below will be executed as a xAgent.

Thanks Armin

importPackage(java.io);
importPackage(org.apache.poi.hwpf);
importPackage(org.apache.poi.hwpf.usermodel);
importPackage(org.apache.poi.poifs.filesystem);

var docID = sessionScope.contentUNID;
var nv:NotesView = database.getView("(allByKey)");
var doc:NotesDocument = nv.getDocumentByKey(docID, true);

var fs:POIFSFileSystem = new POIFSFileSystem(new FileInputStream("empty.doc"));
var wdoc:HWPFDocument = new HWPFDocument(fs);
var wdRange:Range = wdoc.getRange();

wdRange.insertBefore(doc.getItemValueString("title"));
wdRange.insertAfter(doc.getMIMEEntity("content")); !!!doesn'twork

var extCont = facesContext.getExternalContext(); 
var pageResponse = extCont.getResponse();
var pageOutput = pageResponse.getOutputStream();

pageResponse.setContentType("application/vnd.ms-word");
pageResponse.setHeader("Cache-Control", "no-cache");
pageResponse.setHeader("Content-Disposition","inline; filename=export.doc");
wdoc.write(pageOutput);
pageOutput.flush();
pageOutput.close();

facesContext.responseComplete();

Upvotes: 0

Views: 1539

Answers (1)

Panu Haaramo
Panu Haaramo

Reputation: 2932

You will need to use methods of MIMEEntity class to get the content. For example doc.getMIMEEntity("content").getContentAsText(). For this to work you probably need to set session.setConvertMIME(false) before getting the doc.

Another way is to get it as as RichTextItem with doc.getFirstItem("content") and use the methods of RichTextItem class to get the content. In this case you would not set the session.setConvertMIME(false).

Upvotes: 1

Related Questions