[英]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.