【发布时间】:2021-10-03 22:45:40
【问题描述】:
我不明白是什么问题,我正在从上传文件夹中读取 excel 文件,然后我想更新文件并将其另存为新的 xlxs 文件
错误异常详细信息:System.Runtime.InteropServices.COMException:无法访问“System.IO.MemoryStream”。
Excel.Application xlApp = new
Microsoft.Office.Interop.Excel.Application();
Excel.Workbook xlWorkBook;
Excel.Worksheet xlWorkSheet;
object misValue = System.Reflection.Missing.Value;
path = System.IO.Path.Combine(Server.MapPath("~/Uploads/Contactless.xls"));
xlWorkBook = xlApp.Workbooks.Open(path);
xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
xlWorkSheet.Cells[2, 1] = "will test sheet";
using (var stream = new MemoryStream())
{
xlWorkBook.SaveAs(stream);
var content = stream.ToArray();
return File(content,
"application/vnd.openxmlformats-officedocument-spreadsheetml.sheet",
"contactless.xlsx");
}
【问题讨论】:
-
不了解问题的原因是可以的,但您应该提供错误或错误行为的详细信息
-
xlWorkBook.SaveAs(stream);无法访问“System.IO.MemoryStream”。
-
异常详细信息:System.Runtime.InteropServices.COMException:无法访问“System.IO.MemoryStream”。
标签: c# .net excel memorystream