我正在尝试从 zip 存档中读取 excel 文件:
var excelEntry = archive.Entries.Single(entry => Regex.IsMatch(entry.FullName, @"\.xlsx\z", RegexOptions.IgnoreCase));
using (var excelPackage = new ExcelPackage(excelEntry.Open()))
{
}
但是,我收到 NotSupportedException。
(Exception thrown: 'System.NotSupportedException' in System.dll
Additional information: This operation is not supported.)
该文件是一个简单的 .xlsx 文件,没有任何保护。 有什么想法吗?
最佳答案
确实是因为 zip 存档流是只读的,而 ExcelPackage 只接受读/写流。
我做了以下调整:
var entryStream = excelEntry.Open();
using (var ms = new MemoryStream())
using (var excelPackage = new ExcelPackage())
{
entryStream.CopyTo(ms);
excelPackage.Load(ms);
...
}
关于c# - 尝试使用 EPPlus 从 ZipArchive 读取 Excel 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50874958/