2014-08-27 113 views
0

通過Domino Java代理,我使用Apache POI來生成Excel電子表格。代碼首先將文件保存到驅動器;我已驗證我可以在那裏打開文件,並且該文件包含信息。但是,當我通過MIME將其附加到電子郵件中時,我收到一條消息,指出「Excel無法打開文件spreadsheet.xlxs」和「文件格式或文件擴展名無效」。無法打開流式文件附件

下面是我使用的代碼:

MIMEEntity ebody = maildoc.createMIMEEntity(); 
Stream outStream = session.createStream(); 
Stream inStream = session.createStream(); 
inStream.open(entry.getValue(),"binary"); 

do { 
byte[] buffer = inStream.read(32767); 
outStream.write(buffer); 
} while(!inStream.isEOS()); 

inStream.close(); 

MIMEEntity child = ebody.createChildEntity(); 
child.setContentFromBytes(outStream, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", MIMEEntity.ENC_IDENTITY_BINARY); 
MIMEHeader cdHeader = child.createHeader("Content-Disposition"); 
cdHeader.setHeaderVal("attachment; filename="spreadsheet.xlxs"); 
MIMEHeader idHeader = child.createHeader("Content-ID"); 
idHeader.setHeaderVal("spreadsheet.xlxs"); 

outStream.truncate(); 
outStream.close(); 

任何想法,我在哪裏呢?

回答

1

xlsx,而不是xlxs。你有一個錯字。