From b931809534be7d4c670a80b78fd42a1f2eb2497e Mon Sep 17 00:00:00 2001 From: Serghei Cebotari Date: Sun, 21 Jan 2024 23:10:41 +0300 Subject: [PATCH] Do not close workbook on merge if opened --- RhSolutions.AddIn/Services/ExcelReader.cs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/RhSolutions.AddIn/Services/ExcelReader.cs b/RhSolutions.AddIn/Services/ExcelReader.cs index 540c00a..74048c9 100644 --- a/RhSolutions.AddIn/Services/ExcelReader.cs +++ b/RhSolutions.AddIn/Services/ExcelReader.cs @@ -156,6 +156,10 @@ public class ExcelReader : IReader, IDisposable public List<(string, Dictionary)> ReadProducts(string[] files) { + HashSet openedFiles = RhSolutionsAddIn.Excel.Workbooks + .Cast() + .Select(wb => wb.FullName) + .ToHashSet(); _progressBar = new("Открываю исходные файлы...", files.Length); List worksheets = new(); @@ -170,7 +174,11 @@ public class ExcelReader : IReader, IDisposable var result = ReadProducts(worksheets); foreach (var ws in worksheets) { - ws.Parent.Close(); + string file = (string)ws.Parent.FullName; + if (!openedFiles.Contains(file)) + { + ws.Parent.Close(SaveChanges: false); + } } return result; }