Do not close workbook on merge if opened
This commit is contained in:
parent
964bb01a80
commit
b931809534
@ -156,6 +156,10 @@ public class ExcelReader : IReader, IDisposable
|
|||||||
|
|
||||||
public List<(string, Dictionary<Product, double>)> ReadProducts(string[] files)
|
public List<(string, Dictionary<Product, double>)> ReadProducts(string[] files)
|
||||||
{
|
{
|
||||||
|
HashSet<string> openedFiles = RhSolutionsAddIn.Excel.Workbooks
|
||||||
|
.Cast<Workbook>()
|
||||||
|
.Select(wb => wb.FullName)
|
||||||
|
.ToHashSet();
|
||||||
_progressBar = new("Открываю исходные файлы...", files.Length);
|
_progressBar = new("Открываю исходные файлы...", files.Length);
|
||||||
List<Worksheet> worksheets = new();
|
List<Worksheet> worksheets = new();
|
||||||
|
|
||||||
@ -170,7 +174,11 @@ public class ExcelReader : IReader, IDisposable
|
|||||||
var result = ReadProducts(worksheets);
|
var result = ReadProducts(worksheets);
|
||||||
foreach (var ws in 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;
|
return result;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user