通过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();
我出错的任何想法?
答案 0 :(得分:1)
xlsx,而不是xlxs。你有一个错字。