我正在使用模板文件创建新的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();
}