Compare commits
2 Commits
f0fca06beb
...
b931809534
Author | SHA1 | Date | |
---|---|---|---|
b931809534 | |||
964bb01a80 |
@ -4,7 +4,7 @@ namespace RhSolutions.AddIn;
|
||||
|
||||
public sealed class RhSolutionsAddIn : IExcelAddIn
|
||||
{
|
||||
public static readonly Application Excel = (Application)ExcelDnaUtil.Application;
|
||||
public static Application Excel { get; private set; }
|
||||
public static ServiceProvider ServiceProvider { get; private set; }
|
||||
public static IAddInConfiguration Configuration { get; private set; }
|
||||
|
||||
@ -14,6 +14,7 @@ public sealed class RhSolutionsAddIn : IExcelAddIn
|
||||
|
||||
Services.AddHttpClient()
|
||||
.AddMemoryCache()
|
||||
.AddSingleton((Application)ExcelDnaUtil.Application)
|
||||
.AddSingleton<IAddInConfiguration, AddInConfiguration>()
|
||||
.AddSingleton<IDatabaseClient, DatabaseClient>()
|
||||
.AddSingleton<ICurrencyClient, CurrencyClient>()
|
||||
@ -43,6 +44,7 @@ public sealed class RhSolutionsAddIn : IExcelAddIn
|
||||
|
||||
ServiceProvider = Services.BuildServiceProvider();
|
||||
Configuration = ServiceProvider.GetService<IAddInConfiguration>();
|
||||
Excel = ServiceProvider.GetService<Application>();
|
||||
|
||||
EventsUtil.Initialize();
|
||||
|
||||
|
@ -156,6 +156,10 @@ public class ExcelReader : IReader, IDisposable
|
||||
|
||||
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);
|
||||
List<Worksheet> 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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user