当我打开文件时,似乎无法输出一个包含ClosedXML的好文件
我们发现了' filename.xlsx'中某些内容的问题。你想让我们尽可能多地恢复吗?如果您信任此工作簿的来源,请单击“是”。
using (var workbook = new XLWorkbook())
{
var worksheet = workbook.AddWorksheet("name");
worksheet.Row(1).Cell(i + 1).SetValue("test");
worksheet.Row(k + 2).Cell(column.Order + 1).SetValue("test value");
using (var memoryStream = new MemoryStream())
{
workbook.SaveAs(memoryStream);
memoryStream.Seek(0, SeekOrigin.Begin);
return memoryStream.GetBuffer();
}
}
答案 0 :(得分:7)
它使用ToArray()而不是GetBuffer()来解决问题。干杯
using (var workbook = new XLWorkbook())
{
var worksheet = workbook.AddWorksheet("name");
worksheet.Row(1).Cell(i + 1).SetValue("test");
worksheet.Row(k + 2).Cell(column.Order + 1).SetValue("test value");
using (var memoryStream = new MemoryStream())
{
workbook.SaveAs(memoryStream);
memoryStream.Position = 0;
return memoryStream.ToArray();
}
}