gpt4 book ai didi

.net - EPPlus,带有MemoryStream作为电子邮件附件-文件为空

转载 作者:行者123 更新时间:2023-12-03 12:10:02 24 4
gpt4 key购买 nike

我正在构建一个将数据移动到excel文件(使用EPPlus库)的控制台应用程序。我将ExcelPackage保存为MemoryStream,并且要将其附加到电子邮件中。但是,当我收到电子邮件时,Excel文件为空-0个字节。

有什么想法吗?

        MemoryStream outputStream = new MemoryStream();
using (ExcelPackage package = new ExcelPackage(outputStream)) {

// export each facility's rollup and detail to tabs in Excel (two tabs per facility)
ExcelWorksheet facilityWorksheet = package.Workbook.Worksheets.Add(row["facility_id"].ToString());
ExcelWorksheet facilityDetail = package.Workbook.Worksheets.Add(row["facility_id"].ToString() + "-detail");

facilityWorksheet.Cells.LoadFromDataTable(rollupData, true);
facilityDetail.Cells.LoadFromDataTable(rawExceptions, true);

package.Save();
}

这是用于创建电子邮件附件的代码:
Attachment attachment = new Attachment(outputStream, "ECO_exceptions.xlsx", "application/vnd.ms-excel");

最佳答案

经过更多搜索后,我找到了解决方案。显然,在将附件作为附件传递之前,我需要显式设置MemoryStream的起始位置。下面的代码行达到了目的:

outputStream.Position = 0;

关于.net - EPPlus,带有MemoryStream作为电子邮件附件-文件为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12847412/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com