繁体   English   中英

当使用 C# 中的模板创建文件时,如何更新 excel 文件单元格数据?

[英]How to update the excel file cell data, when the file is created using a template in C#?

我正在使用模板文件创建一个新的 excel 文件,但我无法编辑创建的新文件中的内容,请协助。 提前致谢。

FileStream fileStream = new FileStream(filepath, FileMode.Open, FileAccess.Read);

using (ExcelPackage package = new ExcelPackage(fileStream))
{
     package.Save();
}

string name = "filecreated.xlsx";
string fileType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
fileStream.Position = 0;

//return file 
return File(fileStream, fileType, name);```

好像您正在以只读访问模式打开文件

FileStream fileStream = new FileStream(filepath, FileMode.Open, FileAccess.Read);

请你试试看好吗

FileInfo existingFile = new FileInfo(filepath);
using (ExcelPackage package = new ExcelPackage(existingFile))
{
  //As we have not modified the file, its useless to call Save()

  //This will override the opened file
  package.Save();
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM