POI for XPages - save Word document as attachment in rich text field

China☆狼群 提交于 2019-12-06 11:22:13
Knut Herrmann

Save your Word document to file system in a temporary folder and then attach it from there with rtitem.embedObject to your RichTextItem:

var temp = java.lang.System.getProperty("java.io.tmpdir");
var file = new java.io.File(temp + "YourFile.docx"); 
var fileOutputStream = new java.io.FileOutputStream(file);
xwpfdocument.write(fileOutputStream);
fileOutputStream.close();

var doc:NotesDocument = currentDocument.getDocument();
var rdoc:NotesDocument = database.createDocument();
rdoc.appendItemValue("Form", "frmRespTempl");
rdoc.appendItemValue("Subject", "Embedded Word Document");
var rtitem:RichTextItem = rdoc.createRichTextItem("Body");
rtitem.embedObject(lotus.domino.local.EmbeddedObject.EMBED_ATTACHMENT, "",
                   file.getAbsolutePath(), null);
rdoc.makeResponse(doc);
rdoc.save();

If you don't want to save the file into file system then create a MIMEEntity instead and stream the Word content direct to Notes document (Java code snippet as a starting point).

The Notes API requires a file, not a Java object. I would suggest you use the MIME document approach where you Base64 the Doc as mime part

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