我正在使用NPOI创建一个excel工作簿并尝试将其作为附件发送到电子邮件中.我的代码如下:
var wb = new HSSFWorkbook(); //create the workbook using(var ms = new MemoryStream()) { wb.Write(ms); var msg = new MailMessage(); //create email msg.Attachments.Add(new Attachment(ms, "Document.xls", "application/vnd.ms-excel")); client.Send(msg); }
我已经排除了创建工作簿的代码,我已经测试以确保它可以工作(我能够保存文件并打开它而不会出现问题)但是如果你想看到任何东西请问.client
只是我的SmtpClient
.
电子邮件发送没有问题,附件以Document.xls(如预期的那样)出现,但是当我打开它时,我收到以下消息(在Excel 2010中),当我单击"是"打开时,工作表为空.
The file you are trying to open, 'Document.xls', is in a differrent format than specified by the file extension. Verify that the file is not corrupted and is from a trusted source before opening the file. Do you want to open the file now?
据我所知,我正在指定格式.有谁看到我做错了什么?任何帮助,将不胜感激.