我想讀取 Excel 文件,然后找到正確的行并向該行添加一個值,但我收到一條錯誤消息文件已被另一個進程使用。我已將文件添加到 FileStream,所以我不確定為什么會收到此錯誤?System.IO.IOException:“進程無法訪問文件 'D:\repos\FHIRVal\Update.xlsx',因為它正在被另一個進程使用?!眕ublic 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(); }
添加回答
舉報
0/150
提交
取消