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 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
|
'INFORMATION SITE MICROSOFT:
'OFFICE 2003
'MAXIMUM FEUILLES SUR UN CLASSEUR OUVERT:LIMITE PAR PAR MEMOIRE DISPONIBLE
'CAPACITE D'UNE FEUILLE:65536 LIGNES X 256 COLONNES
'OFFICE 2010
'MAXIMUM FEUILLES SUR UN CLASSEUR OUVERT
'CAPACITE D'UNE FEUILLE:1048576 LIGNES X 16384 COLONNES
'1/Noter qu'il ne s'agit que de fonctions utilisateurs UDF(user defined function)
'2/les UDF necessitent un enregistrement avec utilitaire Regasm.exe sur la machine client.
'3/Si l'on veut des Sub on utilise l'Add-In VSTO ou un Document Classeur VSTO
Option Explicit On
Option Strict Off
Option Compare Text
Imports System
Imports System.Windows.Forms
Imports System.Runtime.InteropServices
Imports Microsoft.Win32
Imports Microsoft.Office.Interop
'Interface Publique Com
Public Interface IStatFonctions
Function SeriesDeltaTemp(ByVal TargetRange1 As Excel.Range, ByVal TargetRange2 As Excel.Range) As Object(,)
Function seriesPuissance(ByVal TargetDeltaTemp As Excel.Range, ByVal TargetCapt1Mode As Excel.Range, ByVal TargetCapt2Mode As Excel.Range, ByVal CondTemp As Double) As Object(,)
Function EchoInput(ByVal v1 As Integer) As String
Function DiviserParDeux(ByVal D As Double) As Double
Function DivideParQuatre(ByVal D As Double) As Double
Function ProduitTableau(ByVal nRow As Integer, ByVal nColumn As Integer) As Double(,)
End Interface
'Classe Com Fonction implementant l'interface Publique Com
<ComDefaultInterface(GetType(IStatFonctions))> _
Public Class StatCom
Implements IStatFonctions
#Region "GUID COM"
' Ces GUID fournissent l'identité COM pour cette classe
' et ses interfaces COM. Si vous les modifiez, les clients
' existants ne pourront plus accéder à la classe.
Public Const ClassId As String = "6b03181b-ecd7-4588-8779-ee92e5f78277"
Public Const InterfaceId As String = "866864a1-6689-452b-9068-44ff1be7a46f"
Public Const EventsId As String = "2de8dfe3-de61-4f32-8fca-8d8e29fa871c"
#End Region
' Une classe COM pouvant être créée doit avoir Public Sub New()
' sans paramètre, sinon, la classe ne sera pas
' inscrite dans le Registre COM et ne pourra pas être créée
' via CreateObject.
Public Sub New()
MyBase.New()
End Sub
'fonction chaine
Public Function EchoInput1(ByVal v1 As Integer) As String Implements IStatFonctions.EchoInput
Return "You entered " & v1.ToString
End Function
'fonction numerique 1
Public Function DiviserParDeux1(ByVal D As Double) As Double Implements IStatFonctions.DiviserParDeux
Return D / 2
End Function
'fonction numerique 2
Public Function DivideParQuatre1(ByVal D As Double) As Double Implements IStatFonctions.DivideParQuatre
Return D / 4
End Function
'fonction numerique 3
Public Function ProduitTableau(ByVal nRow As Integer, ByVal nColumn As Integer) As Double(,) Implements IStatFonctions.ProduitTableau
Dim V1(,) As Double
Dim V2(,) As Double
Dim Produit(,) As Double
ReDim V1(nRow, nColumn)
ReDim V2(nRow, nColumn)
ReDim Produit(nRow, nColumn)
For I As Integer = 0 To nRow - 1
For J As Integer = 0 To nColumn - 1
V1(I, J) = 50.5 + I
V2(I, J) = 105.2 + J
Produit(I, J) = V1(I, J) * V2(I, J)
Next
Next I
Return Produit
End Function
Public Function SeriesDeltaTemp(ByVal TargetRange1 As Excel.Range, ByVal TargetRange2 As Excel.Range) As Object(,) Implements IStatFonctions.SeriesDeltaTemp
Dim resultatDeltaTemps(TargetRange1.Rows.Count, TargetRange1.Columns.Count) As Object
For I As Integer = 1 To TargetRange1.Rows.Count
For J As Integer = 1 To TargetRange1.Columns.Count
resultatDeltaTemps(I - 1, J - 1) = TargetRange1(I, J).value - TargetRange2(I, J).value
Next
Next
Return resultatDeltaTemps
End Function
Public Function seriesPuissance(ByVal TargetDeltaTemp As Excel.Range, ByVal TargetCapt1Mode As Excel.Range, ByVal TargetCapt2Mode As Excel.Range, ByVal CondTemp As Double) As Object(,) Implements IStatFonctions.seriesPuissance
Dim resultatPuissTemp(TargetDeltaTemp.Rows.Count, TargetDeltaTemp.Columns.Count) As Object
For I As Integer = 1 To TargetDeltaTemp.Rows.Count
For J As Integer = 1 To TargetDeltaTemp.Columns.Count
If TargetCapt1Mode(I, J).value = "AllGood" And TargetCapt2Mode(I, J).value = "AllGood" Then
If CondTemp > 34.0 Then
resultatPuissTemp(I - 1, J - 1) = 100.0 * TargetDeltaTemp(I, J).value
End If
End If
Next
Next
Return resultatPuissTemp
End Function
<ComRegisterFunctionAttribute()> _
Public Shared Sub RegisterFunction(ByVal type As Type)
Registry.ClassesRoot.CreateSubKey(GetSubKeyName(type))
End Sub
<ComUnregisterFunctionAttribute()> _
Public Shared Sub UnregisterFunction(ByVal type As Type)
Registry.ClassesRoot.CreateSubKey(GetSubKeyName(type))
End Sub
Private Shared Function GetSubKeyName(ByVal type As Type) As String
Dim s As String = "CLSID\\{" + type.GUID.ToString().ToUpper() + "}\\Programmable"
Return s
End Function
End Class |
Partager