使用EPPlus有一个MemoryStream [英] Using EPPlus with a MemoryStream

查看:1705
本文介绍了使用EPPlus有一个MemoryStream的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用EPPlus产生在C#XLSX文件。 。当我实例化一个内存流的ExcelPackage - 我得到的错误:

I am using EPPlus to generate an XLSX file in C#. As soon as I instantiate the ExcelPackage with a memory stream - I get the error:

的写操作过程中出现了磁盘错误(从HRESULT异常:0x8003001D(STG_E_WRITEFAULT ))

"A disk error occurred during a write operation. (Exception from HRESULT: 0x8003001D (STG_E_WRITEFAULT))"

代码是:

MemoryStream stream = new MemoryStream();

using (ExcelPackage package = new ExcelPackage(stream)) {
}

有其他人看到这一点?

推荐答案

其他答案没有完全得到我在那里(Excel工作表总是空),但是这个工作对我来说:

None of the other answers quite got me there (the Excel worksheet was always empty), but this worked for me:

using (var package = new ExcelPackage())
{
    var worksheet = package.Workbook.Worksheets.Add("Worksheet Name");

    worksheet.Cells["A1"].LoadFromCollection(data);

    var stream = new MemoryStream(package.GetAsByteArray());
}

这篇关于使用EPPlus有一个MemoryStream的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆