-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathModExcell.vb
288 lines (236 loc) · 11.2 KB
/
ModExcell.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
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
Imports System
Imports System.ComponentModel
Imports System.Object
Imports System.Drawing
Imports System.String
Imports System.Windows.Forms
Imports System.Drawing.Printing
Imports Microsoft.Office.Interop
Imports Microsoft.Office.Interop.Excel
Imports System.Configuration
Imports System.IO
Module ModExcell
'*******************************************************
'Définition des fonctions Excell du logiciel
'*******************************************************
Public Function lireDansFichierExcel(ByVal nomFichier As String) As Boolean
Dim i, k, Ideb As Integer
Dim str As String
On Error GoTo errorFind
xlApp = CreateObject("Excel.Application")
xlApp.Visible = True ' Rendre visible l'application
wkbObj = xlApp.Workbooks.Open(nomFichier) ' Ouvrir le fichier Excel et affectation
i = 1
k = 0
For i = 1 To 2
With wkbObj.Worksheets(i)
Ideb = 2 'Ideb = numéro de ligne dans la feuille de calcul Excel
If i = 1 Then
If CStr(.Range("B" & Ideb).Value) <> "" Then ' Lecture de la date
DateTest = .Range("B" & Ideb).Value
End If
Ideb = Ideb + 1
Ideb = Ideb + 1
If CStr(.Range("B" & Ideb).Value) <> "" Then ' Lecture du nom de l'essai
nomTest = .Range("B" & Ideb).Value
End If
End If
Ideb = 6 ' Lecture du Miminum requis (Min)
If Valeur(.Range("B" & Ideb).Value) > 0 Then
Min(i - 1) = Valeur(.Range("B" & Ideb).Value)
End If
Ideb = Ideb + 1 ' Lecture du Maximum envisagé (Max)
If Valeur(.Range("B" & Ideb).Value) > 0 Then
Max(i - 1) = Valeur(.Range("B" & Ideb).Value)
End If
Ideb = Ideb + 1 ' Lecture de l'Optimum recherché ou de sa moyenne (Opt)
If Valeur(.Range("B" & Ideb).Value) > 0 Then
Opt(i - 1) = Valeur(.Range("B" & Ideb).Value)
End If
Ideb = Ideb + 1 ' Lecture de l'écart-type de l'Optimum recherché (OptET)
If Valeur(.Range("B" & Ideb).Value) > 0 Then
OptET(i - 1) = Valeur(.Range("B" & Ideb).Value)
End If
Ideb = Ideb + 1 ' Lecture de l'Aversion au risque (Risk)
Ideb = Ideb + 1
If Valeur(.Range("B" & Ideb).Value) > 0 Then
Risk(i - 1) = Valeur(.Range("B" & Ideb).Value)
End If
Ideb = Ideb + 1 ' Lecture de l'Aversion au regret (Rgt)
If Valeur(.Range("B" & Ideb).Value) > 0 Then
Regt(i - 1) = Valeur(.Range("B" & Ideb).Value)
End If
Ideb = Ideb + 1 ' Lecture du mandat de négociation (Mand)
If Valeur(.Range("B" & Ideb).Value) > 0 Then
Mand(i - 1) = Valeur(.Range("B" & Ideb).Value)
End If
Ideb = Ideb + 1 ' Lecture du Degré de confiance (Conf)
Ideb = Ideb + 1
If Valeur(.Range("B" & Ideb).Value) > 0 Then
Conf(i - 1) = Valeur(.Range("B" & Ideb).Value)
End If
Ideb = Ideb + 1 ' Lecture de l'Objectif de négociation (Objectif)
If Valeur(.Range("B" & Ideb).Value) <> Nothing Then
Objectif(i - 1) = Valeur(.Range("B" & Ideb).Value)
End If
Ideb = Ideb + 1 ' Lecture du Degré d'incertitude (Cert)
Ideb = Ideb + 1
If Valeur(.Range("B" & Ideb).Value) > 0 Then
Cert(i - 1) = Valeur(.Range("B" & Ideb).Value)
End If
Ideb = Ideb + 1 ' Lecture de l'Amplitude des variations (Alea)
If Valeur(.Range("B" & Ideb).Value) > 0 Then
Alea(i - 1) = Valeur(.Range("B" & Ideb).Value)
End If
Ideb = Ideb + 1 'Lecture du Coefficient d'affichage (CoeffAff)
If Valeur(.Range("B" & Ideb).Value) > 0 Then
CoeffAff = Valeur(.Range("B" & Ideb).Value)
End If
End With
Next i ' Prochaine feuille de calcul
' Fermeture du fichier Excel
'wkbObj.Close(SaveChanges:=False, Filename:=nomFichier)
wkbObj.Close(SaveChanges:=False)
''wkbObj(nomFichier).close(savechanges:=False)
'wkbObj.Close(nomFichier)
wkbObj = Nothing
' Fermeture du fichier Excel
xlApp.Visible = False
xlApp.Quit()
'For Each item As Process In Process.GetProcessesByName("EXCEL")
' processId += item.Id
'Next
'Process.GetProcessById(processId).Kill()
' Suppression des objets
lireDansFichierExcel = True
Exit Function
errorFind:
lireDansFichierExcel = False
wkbObj.Close()
wkbObj = Nothing
xlApp.Visible = False
xlApp = Nothing
End Function
Public Function EcrireDansFichierExcel(ByVal NomFichier As String) As Boolean
Dim xlApp As Excel.Application
Dim wkbObj As Excel.Workbook
Dim xlSheet As Excel.Worksheet
'Dim xlSheetGraph As Excel.Chart
Dim MyCharts As Excel.ChartObjects
Dim i, j, k, iDeb, Ideb1, iLon As Integer
Dim Str, Str1 As String
Dim Lim1, Lim2 As Single
On Error GoTo errorFind
' ouvrir l'application excel ; Ok
xlApp = CreateObject("Excel.Application")
xlApp.Visible = True ' Rendre visible l'application
' Ouvrir le fichier Excel et affectation
wkbObj = xlApp.Workbooks.Open(NomFichier)
For i = 1 To 2
With wkbObj.Worksheets(i)
' xlSheet = CType(wkbObj.Worksheets("Graphiques"), Excel.Worksheet)
'MyCharts = xlSheet.ChartObjects
'xlSheetGraph = CType(wkbObj.Worksheets(4), Excel.Chart)
'xlSheet = CType(wkbObj.Worksheets("Graphiques"), Excel.Worksheet)
' recherche de la première occurence à droite du caractère "\"
iDeb = 2
.Range("B" & iDeb).Value = DateTest 'Ecriture de la date
iDeb = Inc(iDeb)
.Range("B" & iDeb).Value = NomFichier 'Ecriture du nom de fichier
iDeb = Inc(iDeb)
iDeb = Inc(iDeb)
iDeb = Inc(iDeb)
.Range("B" & iDeb).Value = Min(i - 1) 'Ecriture de la variable Min
iDeb = Inc(iDeb)
.Range("B" & iDeb).Value = Max(i - 1) 'Ecriture de la variable Max
iDeb = Inc(iDeb)
.Range("B" & iDeb).Value = Opt(i - 1) 'Ecriture de la variable Opt
iDeb = Inc(iDeb)
.Range("B" & iDeb).Value = OptET(i - 1) 'Ecriture de la variable OptET
iDeb = Inc(iDeb)
iDeb = Inc(iDeb)
.Range("B" & iDeb).Value = Risk(i - 1) 'Ecriture de la variable Risk
iDeb = Inc(iDeb)
.Range("B" & iDeb).Value = Regt(i - 1) 'Ecriture de la variable Regt
iDeb = Inc(iDeb)
.Range("B" & iDeb).Value = Mand(i - 1) 'Ecriture de la variable Mand
iDeb = Inc(iDeb)
iDeb = Inc(iDeb)
.Range("B" & iDeb).Value = Conf(i - 1) 'Ecriture de la variable Conf
iDeb = Inc(iDeb)
.Range("B" & iDeb).Value = Objectif(i - 1) 'Ecriture de la variable Objectif
iDeb = Inc(iDeb)
iDeb = Inc(iDeb)
.Range("B" & iDeb).Value = Cert(i - 1) 'Ecriture de la variable Cert
iDeb = Inc(iDeb)
.Range("B" & iDeb).Value = Alea(i - 1) 'Ecriture de la variable Alea
iDeb = Inc(iDeb)
.Range("B" & iDeb).Value = CoeffAff 'Ecriture du Coefficient d'affichage (CoeffAff)
End With
Next
With wkbObj.Worksheets(3)
For j = 0 To jmax
.Range("A" & (j + 2)).Value = j + 1
If Nego(j, 0) <> Nothing Then
.Range("B" & (j + 2)).Value = Nego(j, 0)
Else
.Range("B" & (j + 2)).Value = ""
End If
If Nego(j, 1) <> Nothing Then
.Range("C" & (j + 2)).Value = Nego(j, 1)
Else
.Range("C" & (j + 2)).Value = ""
End If
If Nego(j, 2) <> Nothing Then
.Range("D" & (j + 2)).Value = Nego(j, 2)
Else
.Range("D" & (j + 2)).Value = ""
End If
Next
End With
With wkbObj.Worksheets(4)
'Ecriture de toutes les moyennes
.Range("B" & 1).Value = MoyenneNbTours
.Range("C" & 1).Value = MoyenneValAgt1
.Range("D" & 1).Value = MoyenneValAgt2
.Range("F" & 1).Value = MoyenneValAccord
'Ecriture de tous les écarts-types
.Range("B" & 2).Value = EcartTypeNbTours
.Range("C" & 2).Value = EcartTypeValAgt1
.Range("D" & 2).Value = EcartTypeValAgt2
.Range("F" & 2).Value = EcartTypeValAccord
'Ecriture de tous les N
.Range("B" & 3).Value = Ntours
.Range("C" & 3).Value = NAgt1
.Range("D" & 3).Value = NAgt2
.Range("F" & 3).Value = NAccords
j = 6
For i = 0 To NbTirages
.Range("A" & j).Value = j - 5 'Ecriture du numéro du tirage
.Range("B" & j).Value = NegoDyn(i, 0) 'Ecriture du nombre de tours de négociation effectué
.Range("C" & j).Value = NegoDyn(i, 1) 'Ecriture de la proposition initiale si faite par l'agent 1
.Range("D" & j).Value = NegoDyn(i, 2) 'Ecriture de la proposition initiale si faite par l'agent 2
.Range("E" & j).Value = NegoDyn(i, 3) 'Ecriture du résultat de la négociation, 0 = Absence, 1 = Accord
.Range("F" & j).Value = NegoDyn(i, 4) 'Ecriture de la valeur sur laquelle les agents se sont accordés dans le cas d'un accord
j = Inc(j)
Next i
End With
wkbObj.Save()
xlApp.Visible = False
wkbObj.Close(NomFichier) 'Fermeture du fichier
xlApp.Quit()
wkbObj = Nothing
xlApp = Nothing
'Process.GetProcessById(processId).Kill()
EcrireDansFichierExcel = True
Exit Function
errorFind:
MsgBox("Erreur d'enregistrement : " & Err.Description)
EcrireDansFichierExcel = False
wkbObj.Close(NomFichier)
wkbObj = Nothing
xlApp.Visible = False
xlApp.Quit()
xlApp = Nothing
End Function
End Module