Tag: memorystream npoi

如何closures在一个循环内创build多个MemoryStream?

我不能使用内循环,因为那样我就不能发送电子邮件,因为cannot access a closed stream 。 我不能using(MemoryStream memoryStream = new MemoryStream()){the rest of the codes}因为那么只有第一个Excel会有数据,其余的将是空的,文件大小为64 B.我已经validation所有的Excel有数据之前发送它通过电子邮件。 foreach (workbook excel in workbooks) { MemoryStream memoryStream = new MemoryStream(); excel.hssfWorkBook.Write(memoryStream); memoryStream.Position = 0; mailMessage.Attachments.Add(new Attachment(memoryStream, excel.fileName, "application/vnd.ms-excel")); } smtpClient.Send(mailMessage);

MVC3返回文件操作导致间歇性的Excel程序错误

我有一个与此问题密切相关的问题Microsoft Excel错误:“发送命令到程序时出现问题。 从而打开Excel给出了There was an error sending a command to the program错误。 但是,而不是文件存在和正在打开或快捷方式, 我正在使用MVC3与一个动作,产生一堆数据, 生成一个Excel文件 (使用NPOI ),写入一个MemoryStream,然后卡到浏览器使用内置的return File(etc) ActionResult,类似的东西(但缩短在这里,以帮助可读性): return File(myMemoryStream, "application/vnd.ms-excel", "filename.xls"); 你第一次点击链接,触发这个动作,并返回这个文件 – 它出现了错误。 如果你按OK,再试一次就行了,而且会继续工作…永远 现在我知道这可能是与禁用DDE /插件或Excel中的东西有关 – 但由于我生成一个Excel工作簿并将其转储到内存stream而不是打开永久存在于文件系统上的东西, 我我不知道我有什么select来消除这个问题。 有关如何避开它的任何build议? 也许我有错误的MIMEtypes?