Skip to content

Commit 4c086fd

Browse files
committed
Change .xla/.xlam enumeration approach
1 parent 43e189d commit 4c086fd

File tree

1 file changed

+58
-21
lines changed

1 file changed

+58
-21
lines changed

Source/ExcelDna.IntelliSense/Providers/WorkbookIntelliSenseProvider.cs

Lines changed: 58 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -157,33 +157,70 @@ public void Initialize()
157157
RegisterWithXmlProvider(wb);
158158
}
159159
}
160-
if (ExcelDnaUtil.ExcelVersion >= 14.0)
160+
161+
// NOTE: This access to AddIns2 might have caused long load delays
162+
//if (ExcelDnaUtil.ExcelVersion >= 14.0)
163+
//{
164+
// foreach (AddIn addIn in xlApp.AddIns2)
165+
// {
166+
// if (addIn.IsOpen && Path.GetExtension(addIn.FullName) != ".xll")
167+
// {
168+
// // Can it be "Open" and not be loaded?
169+
// var name = addIn.Name;
170+
// Workbook wbAddIn;
171+
// try
172+
// {
173+
// // TODO: Log
174+
// wbAddIn = xlApp.Workbooks[name];
175+
// }
176+
// catch
177+
// {
178+
// // TODO: Log
179+
// continue;
180+
// }
181+
182+
// WorkbookRegistrationInfo regInfo = new WorkbookRegistrationInfo(name);
183+
// _workbookRegistrationInfos[name] = regInfo;
184+
185+
// regInfo.Refresh();
186+
187+
// RegisterWithXmlProvider(wbAddIn);
188+
// }
189+
// }
190+
//}
191+
192+
var loadedAddIns = Integration.XlCall.Excel(Integration.XlCall.xlfDocuments, 2) as object[,];
193+
if (loadedAddIns == null)
194+
{
195+
// This is normal if there are none
196+
Logger.Provider.Verbose($"WorkbookIntelliSenseProvider.Initialize - DOCUMENTS(2) returned null");
197+
return;
198+
}
199+
for (int i = 0; i < loadedAddIns.GetLength(1); i++)
161200
{
162-
foreach (AddIn addIn in xlApp.AddIns2)
201+
var addInName = loadedAddIns[0, i] as string;
202+
if (addInName != null && Path.GetExtension(addInName) != ".xll") // We don't actually expect the .xll add-ins here - and they're taken care of elsewhere
163203
{
164-
if (addIn.IsOpen && Path.GetExtension(addIn.FullName) != ".xll")
204+
// Can it be "Open" and not be loaded?
205+
var name = addInName;
206+
Workbook wbAddIn;
207+
try
165208
{
166-
// Can it be "Open" and not be loaded?
167-
var name = addIn.Name;
168-
Workbook wbAddIn;
169-
try
170-
{
171-
// TODO: Log
172-
wbAddIn = xlApp.Workbooks[name];
173-
}
174-
catch
175-
{
176-
// TODO: Log
177-
continue;
178-
}
209+
// TODO: Log
210+
wbAddIn = xlApp.Workbooks[name];
211+
}
212+
catch
213+
{
214+
// TODO: Log
215+
continue;
216+
}
179217

180-
WorkbookRegistrationInfo regInfo = new WorkbookRegistrationInfo(name);
181-
_workbookRegistrationInfos[name] = regInfo;
218+
WorkbookRegistrationInfo regInfo = new WorkbookRegistrationInfo(name);
219+
_workbookRegistrationInfos[name] = regInfo;
182220

183-
regInfo.Refresh();
221+
regInfo.Refresh();
184222

185-
RegisterWithXmlProvider(wbAddIn);
186-
}
223+
RegisterWithXmlProvider(wbAddIn);
187224
}
188225
}
189226
}

0 commit comments

Comments
 (0)