-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAddIn.vb
62 lines (53 loc) · 2.65 KB
/
AddIn.vb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
Imports System.Linq.Expressions
Imports ExcelDna.Integration
Imports ExcelDna.IntelliSense
Imports ExcelDna.Registration
Public Class AddIn
Implements IExcelAddIn
''' <summary>
''' Gets the <see href="https://www.opentopodata.org/">Open Topo Data </see>HTTP client.
''' </summary>
''' <returns></returns>
Public Shared ReadOnly Property Client As OpenTopoDataHttpClient
''' <summary>
''' Code here will run every time the add-in is loaded.
''' </summary>
Public Sub AutoOpen() Implements IExcelAddIn.AutoOpen
_Client = New OpenTopoDataHttpClient()
RegisterFunctions()
IntelliSenseServer.Install() 'Must run after function registration
End Sub
''' <summary>
''' Code here will run when the add-in is removed in the Add-Ins dialog, but not when Excel closes normally.
''' </summary>
Public Sub AutoClose() Implements IExcelAddIn.AutoClose
Client.Dispose()
IntelliSenseServer.Uninstall()
End Sub
''' <summary>
''' Get all the ExcelFunction functions, process and register
''' </summary>
Private Sub RegisterFunctions()
ExcelRegistration.GetExcelFunctions.
ProcessAsyncRegistrations(nativeAsyncIfAvailable:=False).
ProcessParameterConversions(GetPostAsyncReturnConversionConfig).
RegisterFunctions()
End Sub
''' <summary>
''' This conversion replaces the default #N/A return value of async functions with the #GETTING_DATA value.
''' </summary>
''' <remarks>
''' Source: <see href="https://github.com/Excel-DNA/Registration/blob/master/Source/Samples/Registration.Sample/ExampleAddIn.cs">https://github.com/Excel-DNA/Registration/blob/master/Source/Samples/Registration.Sample/ExampleAddIn.cs</see><br/>
''' </remarks>
''' <returns></returns>
Private Shared Function GetPostAsyncReturnConversionConfig() As ParameterConversionConfiguration
Return New ParameterConversionConfiguration().
AddReturnConversion(Function(type, customAttributes)
Return If(type <> GetType(Object), Nothing,
(CType((Function(returnValue As Object) If(returnValue.Equals(ExcelError.ExcelErrorNA),
ExcelError.ExcelErrorGettingData,
returnValue)),
Expression(Of Func(Of Object, Object)))))
End Function)
End Function
End Class