我想读取excel文件,然后找到正确的行并向该行添加一个值,但我得到的是另一个进程使用的错误消息文件。
我已经将文件添加到FileStream中了,所以我不知道为什么会有这个错误?
System.IO.IOException:“进程无法访问文件'D:\repos\FHIRVal\Update.xlsx‘,因为它正在被其他进程使用。”
public static int UpdateExecelFile(string id, string status)
{
string FilePath = "D:\\repos\\FHIRVal\\Update.xlsx";
using (SLDocument sl = new SLDocument())
{
FileStream fs = new FileStream(FilePath, FileMode.Open);
SLDocument sheet = new SLDocument(fs, "Sheet");
SLWorksheetStatistics stats = sheet.GetWorksheetStatistics();
for (int j = 1; j < stats.EndRowIndex; j++)
{
var value = sheet.GetCellValueAsString(j, 2);
if (value == id)
{
Console.WriteLine(string.Format("{0} --- {1}", "Updating File", id));
string updateRow = string.Format("{0}{1}", "C",j);
sl.SetCellValue(updateRow, status);
}
}
sheet.SaveAs(FilePath);
fs.Close();
}发布于 2019-07-29 19:28:39
我的订单不正确,我需要在床单前有fs.close。
https://stackoverflow.com/questions/57259638
复制相似问题