2016-04-24 64 views
1

我想创建,然后将2个文件添加到与附件相同的文件中。 我该怎么做?请在下面找到我到目前为止所尝试的。 Excel文件来自资源/文件,TXT文件只是在文件保存过程中创建。将Excel文件和.TXT文件添加到XPages中的相同字段

importPackage(org.apache.poi.ss.usermodel); 
var resourcePath = "/SampleExcelFile.xlsx"; 
var bantfile = java.lang.System.getProperty("java.io.tmpdir"); 

var srtEk = "FileName1";  
var excelName = srtEk + ".xlsx"; 
var textFileName = srtEk + +".txt"; 

var excelFilePath = bantfile+"\\"+ excelName; 
var ledesFilePath = bantfile+"\\"+ textFileName; 

var inp = facesContext.getExternalContext().getResourceAsStream(resourcePath); 
var wb = WorkbookFactory.create(inp); 
var sheet = wb.getSheetAt(0); 
var row = sheet.getRow(2); 
if (row == null) 
{ 
    row = sheet.createRow(2); 
} 
var cell = row.getCell(0); 
if (cell == null) 
{ 
    cell = row.createCell(0); 
} 

cell.setCellType(Cell.CELL_TYPE_STRING); 
cell.setCellValue(tempFilePath); 

var fileOut = new java.io.FileOutputStream(excelFilePath); 
wb.write(fileOut); 
fileOut.close(); 

var fileOut = new java.io.FileOutputStream(ledesFilePath); 
wb.write(fileOut); 
fileOut.close(); 

var doc = database.createDocument(); 
doc.replaceItemValue("Form", "frmTest"); 
var rtitem = doc.createRichTextItem("Body"); 
rtitem.embedObject(lotus.domino.local.EmbeddedObject.EMBED_ATTACHMENT, null, excelFilePath , null); 
doc.save(true, false); 

回答

3

您可以随意添加尽可能多的附件到RichText字段。
只需在您的代码中添加另一个embedObject行即可:

rtitem.embedObject(lotus.domino.local.EmbeddedObject.EMBED_ATTACHMENT, null, ledesFilePath, null);