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
|
'1/ Imports InteropService est necessaire pour permettre l'interactiion avec
' une application com(excel)
'2/noter qu'il ne s'agit que de fonctions utilisateurs UDF(user defined function)
'3/si l'on veut des sub on utilise les add-in VSTO
Imports System.Runtime.InteropServices
<ClassInterface(ClassInterfaceType.AutoDual), ComVisible(True)> _
Public Class LibFonctionsExcel
'fonction chaine
Public Function EchoInput(ByVal v1 As Integer) As String
Return "You entered " & v1.ToString
End Function
'fonction numerique 1
Public Function DiviserParDeux(ByVal D As Double) As Double
Return D / 2
End Function
'fonction numerique 2
Public Function DivideParQuatre(ByVal D As Double) As Double
Return D / 4
End Function
'cree un guid et une cle sur le serveur
<ComRegisterFunctionAttribute()> _
Public Shared Sub RegisterFunction(ByVal type As Type)
Microsoft.Win32.Registry.ClassesRoot.CreateSubKey("CLSID\\{" & _
type.GUID.ToString().ToUpper() + "}\\Programmable")
End Sub
'supprime la cle sur le serveur
<ComUnregisterFunctionAttribute()> _
Public Shared Sub UnregisterFunction(ByVal type As Type)
Microsoft.Win32.Registry.ClassesRoot.DeleteSubKey("CLSID\\{" & _
type.GUID.ToString().ToUpper() + "}\\Programmable")
End Sub
End Class |
Partager