IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Visual C++ Discussion :

De Excel 2007 => Visual C++


Sujet :

Visual C++

  1. #1
    Membre confirmé
    Inscrit en
    Novembre 2010
    Messages
    176
    Détails du profil
    Informations forums :
    Inscription : Novembre 2010
    Messages : 176
    Par défaut De Excel 2007 => Visual C++
    Bonjour ¡

    Je m’intéresse au C++ et aux stats et à la modélisation financière.

    Je souhaite utiliser Excel 2007 comme source de séries historiques (de prix … ) , je pourrai alors manipuler ces données avec C++ (j’utilise Visual C++ Express 2010). (NON ! je ne souhaite pas faire autrement ;-) )

    J’ai lu différentes choses sur le sujet et d’autres pas tout à fait sur le sujet (les livres de Steve Dalton sur les add-ins et autres développements pour Excel). Mais je me pose toujours des tas de questions.

    Je ne souhaite pas compliquer dans un premier, en créant l’interface COM.
    Je pense lire mes données dans Excel et les importer sous forme de vectors.

    Le fichier Excel que je souhaite lire, pour la démo s’appelle : C:\Users\Édouard\Desktop\test.xlsx
    Son contenu, 3 colonnes (à partir de ‘A1’):

    2 6 6
    2 2 4
    3 4 4
    5 4 5
    3 4 1
    6 1 2
    2 3 8
    9 5 8
    1 7 7


    Voici le début de mon code (le tout début pourra être utile à d’autres … ) :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    #include <iostream>
    #include <fstream>
    #include<stdio.h>
    #include <cstdlib>
    #include <vector>
     
    using namespace std;
     
    // Microsoft Office Objects
    #import \
    "C:\Program Files\Common Files\Microsoft Shared\OFFICE12\mso.dll" \
    rename("DocumentProperties", "DocumentPropertiesXL") \
    rename("RGB", "RBGXL")
     
    using namespace Office;
     
    // Microsoft VBA Objects
    #import \
    "C:\Program Files\Common Files\Microsoft Shared\VBA\VBA6\vbe6ext.olb"
     
    using namespace VBIDE;
     
    // Excel Application Objects
    #import \
    "C:\Program Files\Microsoft Office\OFFICE12\EXCEL.EXE" \
    rename("DialogBox", "DialogBoxXL") rename("RGB", "RBGXL") \
    rename("DocumentProperties", "DocumentPropertiesXL") \
    rename("ReplaceText", "ReplaceTextXL") \
    rename("CopyFile", "CopyFileXL") \
    exclude("IFont", "IPicture") no_dual_interfaces
     
     
    // convertir les ranges excel en vectors
    vector<double>ExcelRangeTovector(Excel::RangePtr pRange)
    {
         // obtenir le colonnes et les lignes utilisées
         int columns=pRange->Columns->Count;
         int rows=pRange->Rows->Count;
     
         // création du vecteur à la bonne taille
         vector<double> v(columns*rows);
     
         // boucle pour remplir le vecteur
         int index=0;
         for (int r=1; r<=rows; r++)
         {
              for (int c=1; c<=columns; c++)
              {
                   // remplir le vector
                   v[index++]=(((Excel::RangePtr) pRange->Item[r][c])->Value).dblVal;
              }
         }
     
         // obtenir le vector
         return v;
    }

    A partir de ceci, qui rassemble les idées tirées de plusieurs ressources sur internet.

    Je me demande dans quelle mesure (jusqu’à où ?) il faut pointer dans ma feuille Excel. Je ne sais pas non plus s’il est nécessaire d’ ‘activer’ . Enfin, je ne parviens pas à bien utiliser la classe ExcelRangeTovector écrite au-dessus.

    Le début de ma main est comme ceci :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    int main ()
    {
    //try
    //	{
    	//initialisation interface COM
    	CoInitialize(NULL);
    	//Pointeur vers Excel 2007
    	Excel::_ApplicationPtr XL;
    	//Session d’excel
    	XL.CreateInstance(L"Excel.Application");
    	//Excel visible ?
    	XL->Visible = false;
    	// pointeur vers le fichier Excel désiré
    	XL->Workbooks->Open(L"C:\\Users\\Édouard\\Desktop\\test.xlsx");
    	//pointeur vers la première worksheet
    	Excel::_WorksheetPtr pSheet = XL->Sheets->Item[1];
    	// Activation de la 1ère feuille
    	pSheet->Activate();
    	// Pointeur vers les cellules sur la feuille active (ici, la 1ère)
    	Excel::RangePtr pRange = pSheet->Cells;
    	pSheet->Activate();
    	// obtenir le vector dans c++ ???
    	
     …. C’EST LÀ QUE JE NE PARVIENS PAS À MES FINS !!!  COMMENT OBTENIR EFFECTIVEMENT LES CELLULES EXCEL DANS UN VECTEUR ??? COMMENT AFFICHER LE VECTEUR À L’ÉCRAN (COMMENT UTILISER COUT ? ?
    
    
    
    	// Quitter l’application
    	xl->Quit();
    	}
    	//si erreur, le faire savoir !
    	catch(_com_error &error)
    	}
    }

    Quelqu’un aurait-il des idées ?
    Quelqu’un pourrait-il expliquer pédagogiqument ?

    Merci
    Edouard.

  2. #2
    Membre émérite
    Avatar de Gabrielly
    Inscrit en
    Juin 2004
    Messages
    722
    Détails du profil
    Informations forums :
    Inscription : Juin 2004
    Messages : 722
    Par défaut
    Bonjour
    Je peux t'aider pédagogiquement
    mais ça sera un peu long
    Veux-tu?

  3. #3
    Membre confirmé
    Inscrit en
    Novembre 2010
    Messages
    176
    Détails du profil
    Informations forums :
    Inscription : Novembre 2010
    Messages : 176
    Par défaut oui !
    oui oui, je suis preneur de vos explications. en fait, je souhaite bien comprendre comment le transfert excel => visual c++ . j'espère que çà ne vous prendra pas trop de votre temps. merci.

  4. #4
    Membre émérite
    Avatar de Gabrielly
    Inscrit en
    Juin 2004
    Messages
    722
    Détails du profil
    Informations forums :
    Inscription : Juin 2004
    Messages : 722
    Par défaut
    Es-tu famillier avec les MFC?

  5. #5
    Membre confirmé
    Inscrit en
    Novembre 2010
    Messages
    176
    Détails du profil
    Informations forums :
    Inscription : Novembre 2010
    Messages : 176
    Par défaut ...
    j'ai lu sur le sujet et pratiqué peu ..
    je tourne avec la version express de visual c++ .
    tout ce qui est ATL et MFC est plutôt limité (à moins de bidouiller avec DDK de microsoft, mais çà devient compliqué ...)

  6. #6
    Membre émérite
    Avatar de Gabrielly
    Inscrit en
    Juin 2004
    Messages
    722
    Détails du profil
    Informations forums :
    Inscription : Juin 2004
    Messages : 722
    Par défaut
    Bien, mon intervention sera un peu limité mais commence par ajouter deux petits fichiers à ton projet.

    Le fichier OfficeImport.h
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
     
    // Define this according to the Microsoft Office Object Model version you are compiling under
    //#define OFFICE14				// MS Office 2010
    //#define OFFICE12				// MS Office 2007
    //#define OFFICE11				// MS Office 2003
    //#define OFFICE10				// MS Office 2002
    //#define OFFICE9				// MS Office 2000
    //#define OFFICE8				// MS Office 1997
     
    #if defined(OFFICE14)	// Office 2010
     
    #ifndef FRA
    	#ifndef Program_Files_x86
    		#import "C:\\Program Files\\Common Files\\Microsoft Shared\\OFFICE14\\mso.dll" \
    			rename_namespace("Office") \
    			auto_rename
    	#else
    		#import "D:\\Program Files (x86)\\Common Files\\Microsoft Shared\\OFFICE14\\mso.dll" \
    			rename_namespace("Office") \
    			auto_rename
    	#endif
    #else
    	#ifndef Program_Files_x86
    		#import "C:\\Program Files\\Fichiers communs\\Microsoft Shared\\OFFICE14\\mso.dll" \
    			rename_namespace("Office") \
    			auto_rename
    	#else
    		#import "C:\\Program Files (x86)\\Fichiers communs\\Microsoft Shared\\OFFICE14\\mso.dll" \
    			rename_namespace("Office") \
    			auto_rename
    	#endif
    #endif
     
    #elif defined(OFFICE12)	// Office 2007
     
    #ifndef FRA
    	#ifndef Program_Files_x86
    		#import "C:\\Program Files\\Common Files\\Microsoft Shared\\OFFICE12\\mso.dll" \
    			rename_namespace("Office") \
    			auto_rename
    	#else
    		#import "D:\\Program Files (x86)\\Common Files\\Microsoft Shared\\OFFICE12\\mso.dll" \
    			rename_namespace("Office") \
    			auto_rename
    	#endif
    #else
    	#ifndef Program_Files_x86
    		#import "C:\\Program Files\\Fichiers communs\\Microsoft Shared\\OFFICE12\\mso.dll" \
    			rename_namespace("Office") \
    			auto_rename
    	#else
    		#import "C:\\Program Files (x86)\\Fichiers communs\\Microsoft Shared\\OFFICE12\\mso.dll" \
    			rename_namespace("Office") \
    			auto_rename
    	#endif
    #endif
     
    #elif defined(OFFICE11)	// Office 2003
     
    #ifndef FRA
    	#ifndef Program_Files_x86
    		#import "C:\\Program Files\\Common Files\\Microsoft Shared\\OFFICE11\\mso.dll" \
    			rename_namespace("Office") \
    			auto_rename
    	#else
    		#import "C:\\Program Files (x86)\\Common Files\\Microsoft Shared\\OFFICE11\\mso.dll" \
    			rename_namespace("Office") \
    			auto_rename
    	#endif
    #else
    	#ifndef Program_Files_x86
    		#import "C:\\Program Files\\Fichiers communs\\Microsoft Shared\\OFFICE11\\mso.dll" \
    			rename_namespace("Office") \
    			auto_rename
    	#else
    		#import "C:\\Program Files (x86)\\Fichiers communs\\Microsoft Shared\\OFFICE11\\mso.dll" \
    			rename_namespace("Office") \
    			auto_rename
    	#endif
    #endif
     
    #elif defined(OFFICE10) // Office 2002
     
    #ifndef FRA
    	#import "C:\\Program Files\\Common Files\\Microsoft Shared\\OFFICE10\\mso.dll" \
    		rename_namespace("Office"), rename("DocumentProperties", "DocProps")
    #else
    	#import "C:\\Program Files\\Fichiers communs\\Microsoft Shared\\OFFICE10\\mso.dll" \
    		rename_namespace("Office"), rename("DocumentProperties", "DocProps")
    #endif
     
    #elif defined(OFFICE9)	// Office 2000
    	#import "C:\\Program Files\\Microsoft Office\\Office\\mso9.dll" \
    		rename_namespace("Office"), rename("DocumentProperties", "DocProps")
     
    #elif defined (OFFICE8) // Office 1997
    	#import "C:\\Program Files\\Microsoft Office\\Office\\mso97.dll" \
    		rename_namespace("Office"), rename("DocumentProperties", "DocProps")
     
    #endif // OFFICE12
     
    #if defined(VBA6)	// VBA 6
     
    #ifndef FRA
    	#ifndef Program_Files_x86
    		#import "C:\\Program Files\\Common Files\\Microsoft Shared\\VBA\\VBA6\\VBE6EXT.OLB" \
    			rename_namespace("VBA") \
    			auto_rename
    	#else
    		#import "C:\\Program Files (x86)\\Common Files\\Microsoft Shared\\VBA\\VBA6\\VBE6EXT.OLB" \
    			rename_namespace("VBA") \
    			auto_rename
    	#endif	
    #else
    	#ifndef Program_Files_x8
    		#import "C:\\Program Files\\Fichiers communs\\Microsoft Shared\\VBA\\VBA6\\VBE6EXT.OLB" \
    			rename_namespace("VBA") \
    			auto_rename
    	#else
    		#import "C:\\Program Files (x86)\\Fichiers communs\\Microsoft Shared\\VBA\\VBA6\\VBE6EXT.OLB" \
    			rename_namespace("VBA") \
    			auto_rename
    	#endif
    #endif
     
    #endif // VBA6
    et le fichier ExcelImport.h
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
     
    // Define this according to the Excel Object Model version you are compiling under
    //#define EXCEL14				// Excel 2010
    //#define EXCEL12				// Excel 2007
    //#define EXCEL11				// Excel 2003
    //#define EXCEL10				// Excel 2002
    //#define EXCEL9				// Excel 2000
    //#define EXCEL8				// Excel 1997
     
    //#pragma warning(disable:4146)
     
    #define EXCEL_APPLICATION	"Excel.Application"
     
    #if defined(EXCEL14) // Excel 2010
     
    #define EXCEL_APPLICATION_2010	"Excel.Application.14"
    #define OFFICE14
    #define VBA6
    #include "..\Aks.Office\OfficeImport.h"
     
    #ifndef Program_Files_x86
    	#import "C:\\Program Files\\Microsoft Office\\OFFICE14\\Excel.EXE" \
    		rename_namespace("Excel") \
    		auto_rename \
    		include("IFont", "IPicture")
    #else
    	#import "C:\\Program Files (x86)\\Microsoft Office\\OFFICE14\\Excel.EXE" \
    		rename_namespace("Excel") \
    		auto_rename \
    		include("IFont", "IPicture")
    #endif
     
    #elif defined(EXCEL12) // Excel 2007
     
    #define EXCEL_APPLICATION_2007	"Excel.Application.12"
    #define OFFICE12
    #define VBA6
    #include "..\Aks.Office\OfficeImport.h"
     
    #ifndef Program_Files_x86
    	#import "C:\\Program Files\\Microsoft Office\\OFFICE12\\Excel.EXE" \
    		rename_namespace("Excel") \
    		auto_rename \
    		include("IFont", "IPicture")
    #else
    	#import "C:\\Program Files (x86)\\Microsoft Office\\OFFICE12\\Excel.EXE" \
    		rename_namespace("Excel") \
    		auto_rename \
    		include("IFont", "IPicture")
    #endif
     
    #elif defined(EXCEL11) // Excel 2003
     
    #define EXCEL_APPLICATION_2003	"Excel.Application.11"
    #define OFFICE11
    #define VBA6
    #include "..\Aks.Office\OfficeImport.h"
     
    #ifndef Program_Files_x86
    	#import "C:\\Program Files\\Microsoft Office\\OFFICE11\\Excel.EXE" \
    		rename_namespace("Excel") \
    		auto_rename \
    		include("IFont", "IPicture")
    #else
    	#import "C:\\Program Files (x86)\\Microsoft Office\\OFFICE11\\Excel.EXE" \
    		rename_namespace("Excel") \
    		auto_rename \
    		include("IFont", "IPicture")
    #endif
     
    #elif defined(EXCEL10) // Excel 2002
     
    #define EXCEL_APPLICATION_2002	"Excel.Application.10"
    #define OFFICE10
    #define VBA6
    #include "..\Aks.Office\OfficeImport.h"
     
    #import "C:\\Program Files\\Microsoft Office\\OFFICE10\\Excel.EXE" \
    	rename_namespace("Excel") \
    	auto_rename
     
    #elif defined(EXCEL9) // Excel 2000
     
    #define EXCEL_APPLICATION_2000	"Excel.Application.9"
    #define OFFICE9
    #define VBA6
    #include "..\Aks.Office\OfficeImport.h"
     
    #import "C:\\Program Files\\Microsoft Office\\Office\\Excel9.olb" \
    	rename_namespace("Excel") \
    	auto_rename
     
    #elif defined(EXCEL8) // Excel 1997
     
    #define EXCEL_APPLICATION_1997	"Excel.Application.8"
    #define OFFICE8
    #define VBA6
    #include "..\Aks.Office\OfficeImport.h"
     
    #import "C:\\Program Files\\Microsoft Office\\Office\\Excel8.olb" \
    	rename_namespace("Excel") \
    	auto_rename
     
    #endif // EXCEL12
     
    //#pragma warning(default:4146)
    Ces deux fichiers doivent dans un premier tant te permettre de référencer la bonne version d'excel que tu souhaites utiliser.

    Fais correspond les path avec ce que tu as chez toi de l'installation de ton MS Office

    Le fichier ExcelImport fait référence au fichier OfficeImport vérfie donc aussi le path approprié

    Si tu es prêt signale moi

  7. #7
    Membre confirmé
    Inscrit en
    Novembre 2010
    Messages
    176
    Détails du profil
    Informations forums :
    Inscription : Novembre 2010
    Messages : 176
    Par défaut yep !
    çà y est. j'y suis. prêt pour la suite

  8. #8
    Membre émérite
    Avatar de Gabrielly
    Inscrit en
    Juin 2004
    Messages
    722
    Détails du profil
    Informations forums :
    Inscription : Juin 2004
    Messages : 722
    Par défaut
    Je vais te présenter l'organisation générale des objets d'Excel

    1. D'abord tu as l'objet application d'Excel avec ses méthodes au niveau de l'objet application d'Excel. L'objet application maintient une collection des classeurs qui sont ouverts par ton application. C'est le conteneur des classeurs Excel ouverts. Il est judicieux de passer par l'objet application avant d'atteindre ton classeur.

    2. L'objet conteneur des classeurs Excel te perment d'accéder au classeur individuel soit à partir d'un indexe dans la collection soit à partir de son nom. C'est un conteneur au sens propre du terme avec ses méthodes appropriés pour un conteneur des workbooks.

    3. Ensuite tu as l'objet classeur Excel le workbook qui est ton fichier excel proprement dit avec ses méthodes au niveau du workbook.

    4. Le classeur excel donc le workbook contient un conteneur des feuilles excel qui sont les worksheets. Tu accèdes à ces sheets à partir de leurs indexes ou de leurs noms dans la collection avec ses méthodes appropriés pour un conteneur des worksheets.

    5. L'objet feuille d'Excel donc le worksheet contient ses méthodes au niveau de la feuille d'Excel.

    6. A partir de la feuille Excel tu obtiens les objets Range ie les rangés sur ta feuille et sur lesquels tu places tes données, tes formules, tes mises en formes.

    7. Et tu as tout plein d'autres objets Excel comme les Chart et consort, ils sont très nombreux.

    Et donc tu as l'objet application, la collection des classeurs, le classeur, la collection des feuilles, la feuille, les rangées et les autres objets d'Excel.

  9. #9
    Membre émérite
    Avatar de Gabrielly
    Inscrit en
    Juin 2004
    Messages
    722
    Détails du profil
    Informations forums :
    Inscription : Juin 2004
    Messages : 722
    Par défaut
    Au fait je veux t'amener à créer les classes suivantes et dans cet ordre :

    1. CAksExcelApp : C'est l'objet application ou l'instance d'excel
    2. CAksWorkBooks : C'est l'objet collection des classeurs obtenus à partir de l'objet application excel
    3. CAksWorkBook : C'est l'objet classeur issue de la collection des classeur
    4. CAksWorkSheets : C'est l'objet collection des feuilles obtenus à partir de l'objet classeur
    5. CAksWorkSheet : C'est l'objet feuille issue de la collection des feuilles
    6. CAksRange : C'est l'objet rangée obtenue à partir de l'objet feuille


    Et donc pour travailler directement avec une cellule excel tu emprunte le chemin suivant

    CAksExcelApp -> CAksWorkBooks -> CAksWorkBook -> CAksWorkSheets -> CAksWorkSheet -> CAksRange : et je travaille avec les cellules

  10. #10
    Membre émérite
    Avatar de Gabrielly
    Inscrit en
    Juin 2004
    Messages
    722
    Détails du profil
    Informations forums :
    Inscription : Juin 2004
    Messages : 722
    Par défaut
    Mais d'abord il faut chercher un moyen efficace d'avoir une ecriture C++ souple avec les variants ( en d'autres termes par exemple d'affecter directement un CString dans une cellule Excel et vis versa en effectuant une conversion implicite)
    Je te montrerai ma classe CAksVariant

    Ensuite ce que nous allons faire c'est de préparer ces composants Excel en leur rajoutant une surcouche par la définition d'une classe spéciale, une classe template d'un pointeur intelligent comme classe de base définit à l'aide d'une macro. La définition de cette classe de base va nous éviter d'utiliser ces composants de façon brute. Elle a pour objective de produire une syntaxe C++ très souple, propre et puissante.
    Cette classe n'est pas non plus prévu d'être utiliser directement dans notre code. Elle sert plutôt à préparer nos divers classes enfants MFC qui représenteront chaque entité de nos composants Excel principaux.

    Bon, si tu es toujours de la partie, récupère cette classe CAksVariant que tu ranges dans un fichier à part
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
    422
    423
    424
    425
    426
    427
    428
    429
    430
    431
    432
    433
    434
    435
    436
    437
    438
    439
    440
    441
    442
    443
    444
    445
    446
    447
    448
    449
    450
    451
    452
    453
    454
    455
    456
    457
    458
    459
    460
    461
    462
    463
    464
    465
    466
    467
    468
    469
    470
    471
    472
    473
    474
    475
    476
    477
    478
    479
    480
    481
    482
    483
    484
    485
    486
    487
    488
    489
    490
    491
    492
    493
    494
    495
    496
    497
    498
    499
    500
    501
    502
    503
    504
    505
    506
    507
    508
    509
    510
    511
    512
    513
    514
    515
    516
    517
    518
    519
    520
    521
    522
    523
    524
    525
    526
    527
    528
    529
    530
    531
    532
    533
    534
    535
    536
    537
    #pragma once
    
    #include <comutil.h>
    
    namespace AKS
    {
    	template<typename T>
    	class CCastingVariant : public _variant_t
    	{
    	public:
    		typedef CCastingVariant<T> ThisType;
    		typedef _variant_t BaseType;
    
    		// Constructors
    		//
    		inline CCastingVariant() throw()
    			:_variant_t()
    		{
    			m_vtOperation = vt;
    		}
    
    		inline CCastingVariant(const VARIANT& varSrc)
    			:_variant_t(varSrc)
    		{
    			m_vtOperation = vt;
    		}
    
    		inline CCastingVariant(const VARIANT* pSrc)
    			:_variant_t(pSrc)
    		{
    			m_vtOperation = vt;
    		}
    
    		inline CCastingVariant(const _variant_t& varSrc)
    			:_variant_t(varSrc)
    		{
    			m_vtOperation = vt;
    		}
    
    		inline CCastingVariant(const ThisType& varSrc)
    			:_variant_t()
    		{
    			*this = varSrc;
    			m_vtOperation = vt;
    		}
    
    		inline CCastingVariant(VARIANT& varSrc, bool fCopy) // Attach VARIANT if !fCopy
    			:_variant_t(varSrc, fCopy)
    		{
    			m_vtOperation = vt;
    		}          
    
    		inline CCastingVariant(short sSrc, VARTYPE vtSrc = VT_I2)    // Creates a VT_I2, or a VT_BOOL
    			:_variant_t(sSrc, vtSrc)
    		{
    			m_vtOperation = vt;
    		}
    
    		inline CCastingVariant(long lSrc, VARTYPE vtSrc = VT_I4)     // Creates a VT_I4, a VT_ERROR, or a VT_BOOL
    			:_variant_t(lSrc, vtSrc)
    		{
    			m_vtOperation = vt;
    		} 
    
    		inline CCastingVariant(float fltSrc) throw()                                   // Creates a VT_R4
    			:_variant_t(fltSrc)
    		{
    			m_vtOperation = vt;
    		} 
    
    		inline CCastingVariant(double dblSrc, VARTYPE vtSrc = VT_R8)					// Creates a VT_R8, or a VT_DATE
    			:_variant_t(dblSrc, vtSrc)
    		{
    			m_vtOperation = vt;
    		}  
    
    		inline CCastingVariant(COleDateTime dateSrc)									// Creates a VT_DATE
    			:_variant_t((DATE)dateSrc, VT_DATE)
    		{
    			m_vtOperation = vt;
    		}
    
    		inline CCastingVariant(const CY& cySrc) throw()                                // Creates a VT_CY
    			:_variant_t(cySrc)
    		{
    			m_vtOperation = vt;
    		} 
    
    		inline CCastingVariant(const _bstr_t& bstrSrc)                // Creates a VT_BSTR
    			:_variant_t(bstrSrc)
    		{
    			m_vtOperation = vt;
    		} 
    
    		inline CCastingVariant(const wchar_t *pSrc)                   // Creates a VT_BSTR
    			:_variant_t(pSrc)
    		{
    			m_vtOperation = vt;
    		}  
    
    		inline CCastingVariant(const char* pSrc)                     // Creates a VT_BSTR
    			:_variant_t(pSrc)
    		{
    			m_vtOperation = vt;
    		}  
    
    		inline CCastingVariant(const CStringA& rSrc)                     // Creates a VT_BSTR
    			:_variant_t(rSrc.GetString())
    		{
    			m_vtOperation = vt;
    		}   
    
    		inline CCastingVariant(const CStringW& rSrc)                     // Creates a VT_BSTR
    			:_variant_t(rSrc.GetString())
    		{
    			m_vtOperation = vt;
    		}
    
    		inline CCastingVariant(IDispatch* pSrc, bool fAddRef = true) throw()           // Creates a VT_DISPATCH
    			:_variant_t(pSrc, fAddRef)
    		{
    			m_vtOperation = vt;
    		}  
    
    		inline CCastingVariant(bool boolSrc) throw()                                  // Creates a VT_BOOL
    			:_variant_t(boolSrc)
    		{
    			m_vtOperation = vt;
    		}  
    
    		inline CCastingVariant(IUnknown* pSrc, bool fAddRef = true) throw()            // Creates a VT_UNKNOWN
    			:_variant_t(pSrc, fAddRef)
    		{
    			m_vtOperation = vt;
    		}
    
    		inline CCastingVariant(const DECIMAL& decSrc) throw()                          // Creates a VT_DECIMAL
    			:_variant_t(decSrc)
    		{
    			m_vtOperation = vt;
    		}  
    
    		inline CCastingVariant(BYTE bSrc) throw()                                      // Creates a VT_UI1
    			:_variant_t(bSrc)
    		{
    			m_vtOperation = vt;
    		}          
    
    		inline CCastingVariant(char cSrc) throw()                                      // Creates a VT_I1
    			:_variant_t(cSrc)
    		{
    			m_vtOperation = vt;
    		}  
    
    		inline CCastingVariant(unsigned short usSrc) throw()                           // Creates a VT_UI2
    			:_variant_t(usSrc)
    		{
    			m_vtOperation = vt;
    		}   
    
    		inline CCastingVariant(unsigned long ulSrc) throw()                            // Creates a VT_UI4
    			:_variant_t(ulSrc)
    		{
    			m_vtOperation = vt;
    		}  
    
    		inline CCastingVariant(int iSrc) throw()                                       // Creates a VT_INT
    			:_variant_t(iSrc)
    		{
    			m_vtOperation = vt;
    		} 
    
    		inline CCastingVariant(unsigned int uiSrc) throw()                             // Creates a VT_UINT
    			:_variant_t(uiSrc)
    		{
    			m_vtOperation = vt;
    		} 
    
    #if (_WIN32_WINNT >= 0x0501)
    		inline CCastingVariant(__int64 i8Src) throw()                                  // Creates a VT_I8
    			:_variant_t(i8Src)
    		{
    			m_vtOperation = vt;
    		}  
    
    		inline CCastingVariant(unsigned __int64 ui8Src) throw()                        // Creates a VT_UI8
    			:_variant_t(ui8Src)
    		{
    			m_vtOperation = vt;
    		}          
    #endif
    
    		// Destructor
    		//
    		~CCastingVariant() throw()
    		{
    		}
    
    		// AKS Extractors
    		//
    
    		inline operator BaseType() const throw()
    		{
    			return *(BaseType*) this;
    		}
    
    		inline operator CStringA() const throw() // Extracts as CStringA object
    		{
    			_bstr_t bstr = *this;
    			return CStringA(bstr.GetBSTR());
    		}
    
    		// base class doesn't extract a double as date so CAksVariant do it itseft
    		inline operator double() const // Extracts a double from a VT_R8 or a VT_DATE
    		{
    			if (V_VT(this) == VT_R8) {
    				return V_R8(this); 
    			}
    			else if (V_VT(this) == VT_DATE) {
    				return V_DATE(this); 
    			}
    
    			BaseType varDest;
    			varDest.ChangeType(VT_R8, this);
    
    			return V_R8(&varDest);
    		}
    
    		inline ThisType& operator=(const ThisType& varSrc)
    		{
    			const BaseType& varBaseSrc = varSrc;
    			BaseType::operator=(varBaseSrc);
    			m_vtOperation = varSrc.m_vtOperation;
    			return *this;
    		}
    
    		inline ThisType& operator=(const CStringA& strSrc)    // Assign a CStringA
    		{
    			BaseType::operator=(strSrc);
    			return *this;
    		}
    
    		inline ThisType& operator=(const CStringW& strSrc)    // Assign a CStringW
    		{
    			BaseType::operator=(strSrc);
    			return *this;
    		}
    
    		inline ThisType& operator=(double dblSrc)			// Assign a double
    		{
    			BaseType::operator=(dblSrc);
    			return *this;
    		}
    
    		inline ThisType& operator=(const COleDateTime& dateSrc)    // Assign a COleDateTime
    		{
    			BaseType::operator=((DATE)dateSrc);
    			return *this;
    		}
    
    		inline bool IsEmpty() const
    		{
    			return (V_VT(this) == VT_EMPTY);
    		}
    
    		inline bool IsNull() const
    		{
    			return (V_VT(this) == VT_NULL);
    		}
    
    		// Comparison operations
    		//
    		VARTYPE m_vtOperation;
    
    		enum { VT_BSTR_NOCASE = -1 };
    
    		inline bool operator==(const ThisType& varValue2) const throw()
    		{
    			if( IsEmpty() && varValue2.IsEmpty() )
    				return true;
    			else if( IsEmpty() && !varValue2.IsEmpty() )
    				return false;
    			else if( !IsEmpty() && varValue2.IsEmpty() )
    				return false;
    
    			const BaseType& Value2 = varValue2;
    			const BaseType& Value1 = *this;
    
    			switch(m_vtOperation)
    			{
    			case VT_I1:			return ((char)Value1 == (char)Value2)? true: false;
    			case VT_I2:			return ((short)Value1 == (short)Value2)? true: false;
    			case VT_I4:			return ((long)Value1 == (long)Value2)? true: false;
    
    			case VT_CY:			return (((CY)Value1).int64 == ((CY)Value2).int64)? true: false;
    			case VT_DECIMAL:	return (((DECIMAL)Value1).Lo64 == ((DECIMAL)Value2).Lo64)? true: false;
    
    			case VT_UI1:		return ((BYTE)Value1 == (BYTE)Value2)? true: false;
    			case VT_UI2:		return ((unsigned short)Value1 == (unsigned short)Value2)? true: false;
    			case VT_UI4:		return ((unsigned long)Value1 == (unsigned long)Value2)? true: false;
    
    			case VT_INT:		return ((int)Value1 == (int)Value2)? true: false;
    			case VT_UINT:		return ((unsigned int)Value1 == (unsigned int)Value2)? true: false;
    
    #if (_WIN32_WINNT >= 0x0501)
    			case VT_I8:			return ((__int64)Value1 == (__int64)Value2)? true: false;
    			case VT_UI8:		return ((unsigned __int64)Value1 == (unsigned __int64)Value2)? true: false;
    #endif
    
    			case VT_R4:			return ((float)Value1 == (float)Value2)? true: false;
    			case VT_R8:			return ((double)Value1 == (double)Value2)? true: false;
    			case VT_DATE:		return ((double)Value1 == (double)Value2)? true: false;
    
    			case VT_BSTR:       return ((_bstr_t)Value1 == (_bstr_t)Value2)? true: false;
    			case VT_BSTR_NOCASE:
    				{
    					CStringA strValue1 = Value1;
    					CStringA strValue2 = Value2;
    					return (strValue1.CompareNoCase(strValue2) == 0)? true: false;
    				}
    
    			default:
    				ATLASSERT(FALSE);
    				return false;
    			}
    		}
    		
    		inline bool operator!=(const ThisType& varValue) const throw()
    		{
    			return !(*this == varValue);
    		}
    
    		inline bool operator<(const ThisType& varValue2) const throw()
    		{
    			if( IsEmpty() && varValue2.IsEmpty() )
    				return false;
    			else if( IsEmpty() && !varValue2.IsEmpty() )
    				return true;
    			else if( !IsEmpty() && varValue2.IsEmpty() )
    				return false;
    
    			const BaseType& Value2 = varValue2;
    			const BaseType& Value1 = *this;
    
    			switch(m_vtOperation)
    			{
    			case VT_I1:			return ((char)Value1 < (char)Value2)? true: false;
    			case VT_I2:			return ((short)Value1 < (short)Value2)? true: false;
    			case VT_I4:			return ((long)Value1 < (long)Value2)? true: false;
    
    			case VT_CY:			return (((CY)Value1).int64 < ((CY)Value2).int64)? true: false;
    			case VT_DECIMAL:	return (((DECIMAL)Value1).Lo64 < ((DECIMAL)Value2).Lo64)? true: false;
    
    			case VT_UI1:		return ((BYTE)Value1 < (BYTE)Value2)? true: false;
    			case VT_UI2:		return ((unsigned short)Value1 < (unsigned short)Value2)? true: false;
    			case VT_UI4:		return ((unsigned long)Value1 < (unsigned long)Value2)? true: false;
    
    			case VT_INT:		return ((int)Value1 < (int)Value2)? true: false;
    			case VT_UINT:		return ((unsigned int)Value1 < (unsigned int)Value2)? true: false;
    
    #if (_WIN32_WINNT >= 0x0501)
    			case VT_I8:			return ((__int64)Value1 < (__int64)Value2)? true: false;
    			case VT_UI8:		return ((unsigned __int64)Value1 < (unsigned __int64)Value2)? true: false;
    #endif
    
    			case VT_R4:			return ((float)Value1 < (float)Value2)? true: false;
    			case VT_R8:			return ((double)Value1 < (double)Value2)? true: false;
    			case VT_DATE:		return ((double)Value1 < (double)Value2)? true: false;
    
    			case VT_BSTR:		return ((_bstr_t)Value1 < (_bstr_t)Value2)? true: false;
    
    			default:
    				ATLASSERT(FALSE);
    				return false;
    			}
    		}
    
    		inline bool operator>(const ThisType& varValue2) const throw()
    		{
    			if( IsEmpty() && varValue2.IsEmpty() )
    				return false;
    			else if( IsEmpty() && !varValue2.IsEmpty() )
    				return false;
    			else if( !IsEmpty() && varValue2.IsEmpty() )
    				return true;
    
    			const BaseType& Value2 = varValue2;
    			const BaseType& Value1 = *this;
    
    			switch(m_vtOperation)
    			{
    			case VT_I1:			return ((char)Value1 > (char)Value2)? true: false;
    			case VT_I2:			return ((short)Value1 > (short)Value2)? true: false;
    			case VT_I4:			return ((long)Value1 > (long)Value2)? true: false;
    
    			case VT_CY:			return (((CY)Value1).int64 > ((CY)Value2).int64)? true: false;
    			case VT_DECIMAL:	return (((DECIMAL)Value1).Lo64 > ((DECIMAL)Value2).Lo64)? true: false;
    
    			case VT_UI1:		return ((BYTE)Value1 > (BYTE)Value2)? true: false;
    			case VT_UI2:		return ((unsigned short)Value1 > (unsigned short)Value2)? true: false;
    			case VT_UI4:		return ((unsigned long)Value1 > (unsigned long)Value2)? true: false;
    
    			case VT_INT:		return ((int)Value1 > (int)Value2)? true: false;
    			case VT_UINT:		return ((unsigned int)Value1 > (unsigned int)Value2)? true: false;
    
    #if (_WIN32_WINNT >= 0x0501)
    			case VT_I8:			return ((__int64)Value1 > (__int64)Value2)? true: false;
    			case VT_UI8:		return ((unsigned __int64)Value1 > (unsigned __int64)Value2)? true: false;
    #endif
    
    			case VT_R4:			return ((float)Value1 > (float)Value2)? true: false;
    			case VT_R8:			return ((double)Value1 > (double)Value2)? true: false;
    			case VT_DATE:		return ((double)Value1 > (double)Value2)? true: false;
    
    			case VT_BSTR:		return ((_bstr_t)Value1 > (_bstr_t)Value2)? true: false;
    
    			default:
    				ATLASSERT(FALSE);
    				return false;
    			}
    		}
    
    		inline bool operator<=(const ThisType& varValue2) const throw()
    		{
    			if( IsEmpty() && varValue2.IsEmpty() )
    				return true;
    			else if( IsEmpty() && !varValue2.IsEmpty() )
    				return true;
    			else if( !IsEmpty() && varValue2.IsEmpty() )
    				return false;
    
    			const BaseType& Value2 = varValue2;
    			const BaseType& Value1 = *this;
    
    			switch(m_vtOperation)
    			{
    			case VT_I1:			return ((char)Value1 <= (char)Value2)? true: false;
    			case VT_I2:			return ((short)Value1 <= (short)Value2)? true: false;
    			case VT_I4:			return ((long)Value1 <= (long)Value2)? true: false;
    
    			case VT_CY:			return (((CY)Value1).int64 <= ((CY)Value2).int64)? true: false;
    			case VT_DECIMAL:	return (((DECIMAL)Value1).Lo64 <= ((DECIMAL)Value2).Lo64)? true: false;
    
    			case VT_UI1:		return ((BYTE)Value1 <= (BYTE)Value2)? true: false;
    			case VT_UI2:		return ((unsigned short)Value1 <= (unsigned short)Value2)? true: false;
    			case VT_UI4:		return ((unsigned long)Value1 <= (unsigned long)Value2)? true: false;
    
    			case VT_INT:		return ((int)Value1 <= (int)Value2)? true: false;
    			case VT_UINT:		return ((unsigned int)Value1 <= (unsigned int)Value2)? true: false;
    
    #if (_WIN32_WINNT >= 0x0501)
    			case VT_I8:			return ((__int64)Value1 <= (__int64)Value2)? true: false;
    			case VT_UI8:		return ((unsigned __int64)Value1 <= (unsigned __int64)Value2)? true: false;
    #endif
    
    			case VT_R4:			return ((float)Value1 <= (float)Value2)? true: false;
    			case VT_R8:			return ((double)Value1 <= (double)Value2)? true: false;
    			case VT_DATE:		return ((double)Value1 <= (double)Value2)? true: false;
    
    			case VT_BSTR:		return ((_bstr_t)Value1 <= (_bstr_t)Value2)? true: false;
    
    			default:
    				ATLASSERT(FALSE);
    				return false;
    			}
    		}
    
    		inline bool operator>=(const ThisType& varValue2) const throw()
    		{
    			if( IsEmpty() && varValue2.IsEmpty() )
    				return true;
    			else if( IsEmpty() && !varValue2.IsEmpty() )
    				return false;
    			else if( !IsEmpty() && varValue2.IsEmpty() )
    				return true;
    
    			const BaseType& Value2 = varValue2;
    			const BaseType& Value1 = *this;
    
    			switch(m_vtOperation)
    			{
    			case VT_I1:			return ((char)Value1 >= (char)Value2)? true: false;
    			case VT_I2:			return ((short)Value1 >= (short)Value2)? true: false;
    			case VT_I4:			return ((long)Value1 >= (long)Value2)? true: false;
    
    			case VT_CY:			return (((CY)Value1).int64 >= ((CY)Value2).int64)? true: false;
    			case VT_DECIMAL:	return (((DECIMAL)Value1).Lo64 >= ((DECIMAL)Value2).Lo64)? true: false;
    
    			case VT_UI1:		return ((BYTE)Value1 >= (BYTE)Value2)? true: false;
    			case VT_UI2:		return ((unsigned short)Value1 >= (unsigned short)Value2)? true: false;
    			case VT_UI4:		return ((unsigned long)Value1 >= (unsigned long)Value2)? true: false;
    
    			case VT_INT:		return ((int)Value1 >= (int)Value2)? true: false;
    			case VT_UINT:		return ((unsigned int)Value1 >= (unsigned int)Value2)? true: false;
    
    #if (_WIN32_WINNT >= 0x0501)
    			case VT_I8:			return ((__int64)Value1 >= (__int64)Value2)? true: false;
    			case VT_UI8:		return ((unsigned __int64)Value1 >= (unsigned __int64)Value2)? true: false;
    #endif
    
    			case VT_R4:			return ((float)Value1 >= (float)Value2)? true: false;
    			case VT_R8:			return ((double)Value1 >= (double)Value2)? true: false;
    			case VT_DATE:		return ((double)Value1 >= (double)Value2)? true: false;
    
    			case VT_BSTR:		return ((_bstr_t)Value1 >= (_bstr_t)Value2)? true: false;
    
    			default:
    				ATLASSERT(FALSE);
    				return false;
    			}
    		}
    
    		static T* CastFromVariant(VARIANT var)
    		{
    			if(var.vt != VT_BYREF || var.byref == NULL)
    				return NULL;
    			return (T*) var.byref;
    		}
    
    		static VARIANT CastToVariant(T* pT)
    		{
    			if(pT == NULL)
    				return CComVariant();
    
    			VARIANT var;
    			var.byref = (void*) pT;
    			var.vt = VT_BYREF;
    			return var;
    		}
    
    	};  // class CCastingVariant
    
    
    	typedef CCastingVariant<void> CAksVariant;
    
    } // namespace AKS
    J'attend ta réaction

  11. #11
    Membre confirmé
    Inscrit en
    Novembre 2010
    Messages
    176
    Détails du profil
    Informations forums :
    Inscription : Novembre 2010
    Messages : 176
    Par défaut ouch !
    bonsoir !

    Gabrielly, ma première réaction a été lacrimale
    J'avoue que suis un peu dépassé par ce qu'il faut mettre ou non dans les classes ...

    Le basic 1.1 sur mon amstrad 6128 (que j'ai encore!) c'était bien plus simple !!! il faut dire que l'on était plus limité !

    Dans mon futur *.cpp principal, je souhaite demander à l'utilisateur le nom (avec chemin complet, ce sera plus simple)

    Voici une proposition (pas mal soulignée en rouge dans dans visual C++ )

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    //CAksExcelApp : l'objet application ou l'instance d'excel
    class CAksExcelApp
    {
    public:
    	#include "ExcelImport.h"
    	//Initialise l'interface COM
    	CoInitialize(NULL);
    	//Pointeur vers l'application Excel
    	Excel::_ApplicationPtr XL;
    	//Instancie Excel
    	XL.CreateInstance(L"Excel.Application");
    }
    ;
     
    //CAksWorkBooks : l'objet collection des classeurs obtenus à partir de l'objet application excel
    class CAksExcelApp: public CAksWorkBooks
    {
    public:
    	XL->Workbooks;
    }
    ;
     
    //CAksWorkBook : l'objet classeur issue de la collection des classeur
    class CAksWorkBooks: public CAksWorkBook
    {
    public:
    	char nom_fichier
    	XL->Workbooks->Open(L"%nom_fichier");
    }
    ;
     
    //CAksWorkSheets : l'objet collection des feuilles obtenus à partir de l'objet classeur
    class CAksWorkBook: public CAksWorkSheets
    {
    public:
    	XL->ActiveWorkbook
    }
    ;
     
    // CAksWorkSheet : l'objet feuille issue de la collection des feuilles 
    class CAksWorkSheets: public CAksWorkSheet
    {
    public:
    	float nom_feuille_excel;
    	XL->Sheets->Item[nom_feuille_excel];
    }
    ;
     
    // CAksRange : l'objet rangée obtenue à partir de l'objet feuille
    class CAksWorkSheet: public CAksRange
     
    {
    public:
    	Range->Activate();
    }
    ;
    voilà, je ne suis pas très satisfait de moi ....

    édouard

  12. #12
    Membre émérite
    Avatar de Gabrielly
    Inscrit en
    Juin 2004
    Messages
    722
    Détails du profil
    Informations forums :
    Inscription : Juin 2004
    Messages : 722
    Par défaut
    Allons-y doucement.
    Est-ce que tu as rangé la classe CAksVariant dans un fichier soit AksVariant.h?
    Fais d'abord ça
    Ensuite range le code suivant dans le fichier AksComPtrT.h
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
     
    #pragma once
     
    #include <comdef.h>
    #include <comdefsp.h>
     
    namespace AKS
    {
     
    #define AKS_CONSTRUCT_COM_PTR_T(theClass, theBaseClass) \
    	public: \
    		theClass() \
    		{ \
    		} \
    		explicit theClass( \
    			const CLSID& clsid,	IUnknown* pOuter = NULL, DWORD dwClsContext = CLSCTX_ALL) \
    			:CAksComPtrT<theBaseClass>(clsid, pOuter, dwClsContext) \
    		{ \
    		} \
    		explicit theClass(  \
    			LPCWSTR str, IUnknown* pOuter = NULL, DWORD dwClsContext = CLSCTX_ALL) \
    			:CAksComPtrT<theBaseClass>(str, pOuter, dwClsContext) \
    		{ \
    		} \
    		explicit theClass(  \
    			LPCSTR str, IUnknown* pOuter = NULL, DWORD dwClsContext = CLSCTX_ALL) \
    			:CAksComPtrT<theBaseClass>(str, pOuter, dwClsContext) \
    		{ \
    		} \
    		theClass(const theBaseClass& sp) throw() \
    			:CAksComPtrT<theBaseClass>(sp) \
    		{ \
    		} \
    		theClass& operator=(theBaseClass p) \
    		{ \
    			HRESULT hr = _QueryInterface(p); \
    			if (FAILED(hr) && (hr != E_NOINTERFACE)) { \
    				_com_issue_error(hr); \
    			} \
    			return *this; \
    		}
     
    // T class must inherit directly of indirectly from _com_ptr_t
     
    	template< class T >
    	class CAksComPtrT : public T
    	{
    	public:
    		typedef T baseType;
    		typedef CAksComPtrT<T> thisType;
     
    		CAksComPtrT()
    		{
    		}
     
    		explicit CAksComPtrT(
    			const CLSID& clsid,	IUnknown* pOuter = NULL, DWORD dwClsContext = CLSCTX_ALL)
    			:T(clsid, pOuter, dwClsContext)
    		{
    		}
     
    		explicit CAksComPtrT(
    			LPCWSTR str, IUnknown* pOuter = NULL, DWORD dwClsContext = CLSCTX_ALL)
    			:T(str, pOuter, dwClsContext)
    		{
    		}
     
    		explicit CAksComPtrT( 
    			LPCSTR str, IUnknown* pOuter = NULL, DWORD dwClsContext = CLSCTX_ALL)
    			:T(str, pOuter, dwClsContext)
    		{
    		}
     
    		CAksComPtrT(const T& sp) throw()
    			:T(sp)
    		{
    		}
     
    	protected:
    		template<typename _InterfacePtr>
    		HRESULT _QueryInterface(_InterfacePtr p) throw()
    		{
    			HRESULT hr;
    			if (p != NULL)
    			{
    				Interface* pInterface;
    				hr = p->QueryInterface(GetIID(), reinterpret_cast<void**>(&pInterface));
    				baseType::Attach(SUCCEEDED(hr)? pInterface: NULL);
    			}
    			else
    			{
    				baseType::operator=(static_cast<Interface*>(NULL));
    				hr = E_NOINTERFACE;
    			}
    			return hr;
    		}
     
    	}; // class CAksComPtrT
     
    } // namespace AKS
    Il s'agit du code du point intelligent CAksComPtrT qui dérive indirectement de _com_ptr_t définit dans comdef.h. Ce pointeur va te faciliter la vie dans la minipulation des _com_ptr_t en toute transparence

    Si tu as les fichiers AksVariant.h et AksComPtrT.h alors on peut avancer maintenant dans la définition de nos classes CAksExcelApp, CAksWorkBooks, CAksWorkBook, CAksWorkSheets, CAksWorkSheet et CAksRange

  13. #13
    Membre confirmé
    Inscrit en
    Novembre 2010
    Messages
    176
    Détails du profil
    Informations forums :
    Inscription : Novembre 2010
    Messages : 176
    Par défaut
    bonjour Gabrielly.
    oui, çà y est, j'ai le tout.
    mes AksVariant.h et AksComPtrT.h sont créés.
    et j'ai aussi ExcelImport.h et OfficeImport.h

  14. #14
    Membre émérite
    Avatar de Gabrielly
    Inscrit en
    Juin 2004
    Messages
    722
    Détails du profil
    Informations forums :
    Inscription : Juin 2004
    Messages : 722
    Par défaut
    Ok,
    Voici la classe CAksExcelApp dans son fichier AksExcelApp.h
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
     
     
    #pragma once
     
    namespace AKS
    {
    	namespace Automation
    	{
    		namespace AksExcel
    		{
    			class AFX_EXT_CLASS CAksExcelApp : public CAksComPtrT<Excel::_ApplicationPtr>
    			{
    				AKS_CONSTRUCT_COM_PTR_T(CAksExcelApp, Excel::_ApplicationPtr)
     
    			public:
    				HRESULT CreateInstance(const CLSID& rclsid) throw();
    				HRESULT CreateInstance(LPCWSTR clsidString) throw();
    				HRESULT CreateInstance(LPCSTR clsidStringA) throw();
     
    			public:
    				Excel::_WorkbookPtr CreateWorkBook();
    				Excel::_WorkbookPtr OpenWorkBook(CString strFileName);
    				Excel::_WorkbookPtr OpenWorkBook(CString strFileName, CString strPassword);
    				Excel::_WorkbookPtr GetActiveWorkBook();
     
    				CAksWorkBooks GetWorkBookCollection();
     
    				HWND GetHwnd();
    				HINSTANCE GetHinstance();
     
    				CString GetPath();
    				CString GetVersion();
     
    				bool GetUserControl();
    				void PutUserControl(bool bUserCtrl);
     
    				bool GetVisible();
    				void PutVisible(bool bVisible);
     
    			public:
    				void Close();
    				void CloseAllUserExcelApp();
    				void Quit();
     
    			}; // class CAksExcelApp
     
    		} // namespace AksExcel
    	} // namespace Automation
    } // namespace AKS
    Voici la classe CAksWorkBooks dans son fichier AksWorkBooks.h
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
     
    #pragma once
     
    namespace AKS
    {
    	namespace Automation
    	{
    		namespace AksExcel
    		{
    			class AFX_EXT_CLASS CAksWorkBooks : public CAksComPtrT<Excel::WorkbooksPtr>
    			{
    				AKS_CONSTRUCT_COM_PTR_T(CAksWorkBooks, Excel::WorkbooksPtr)
     
    			public:
    				IDispatchPtr GetItem(long nItemIndex);
    				IDispatchPtr GetItem(CString strItemName, bool bFullName = true);
     
    				CString GetWorkBookName(long nItemIndex, bool bFullName = true);
    				long GetWorkBookIndex(CString strItemName, bool bFullName = true);
     
    				long GetWorkBookCount();
    				POSITION GetFirstWorkBookPosition();
    				IDispatchPtr GetNextWorkBook(POSITION& pos);
     
    				HRESULT Close();
     
    			private:
    				long m_Pos;
    			}; // class CAksWorkBooks
     
    		} // namespace AksExcel
    	} // namespace Automation
    } // namespace AKS
    Voici la classe CAksWorkBook dans son fichier AksWorkBook.h
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
     
    #pragma once
     
    namespace AKS
    {
    	namespace Automation
    	{
    		namespace AksExcel
    		{
    			class AFX_EXT_CLASS CAksWorkBook : public CAksComPtrT<Excel::_WorkbookPtr>
    			{
    				AKS_CONSTRUCT_COM_PTR_T(CAksWorkBook, Excel::_WorkbookPtr)
     
    			public:
    				IDispatchPtr CreateWorkSheet();
    				IDispatchPtr OpenWorkSheet(CString strName);
    				IDispatchPtr OpenWorkSheet(long nIndex);
     
    				CAksWorkSheets GetWorkSheetCollection();
     
    			public:
    				bool Show(LPCTSTR pszWorkSheetName = NULL);
    				bool Show(long nWorkSheetIndex);
     
    			public:
    				void Close(bool bSaveChange = false);
     
    			public:
    				HRESULT SaveAs(CString strXlFile, short XlAccessMode = Excel::xlShared);
    				HRESULT SaveAs(
    					CString strXlFile, 
    					CString strPassword, 
    					CString strWriteResPassword, 
    					bool bReadOnly = false, 
    					short XlAccessMode = Excel::xlShared);
    				HRESULT Save();
    				HRESULT SaveCopyAs(CString strXlFile);
     
    				CString GetName(void);
    				CString GetFullName(void);
     
    			public:
    				Excel::XlSaveConflictResolution GetConflictResolution();
    				void PutConflictResolution(Excel::XlSaveConflictResolution RHS);
     
    			public:
    				bool HasPassword();
    				CString GetPassword();
    				void SetPassword(CString strPassword);
     
    				CString GetWritePassword();
    				void SetWritePassword(CString strWritePassword);
     
    				CString GetPasswordEncryptionProvider();
    				CString GetPasswordEncryptionAlgorithm();
    				long GetPasswordEncryptionKeyLength();
    				bool GetPasswordEncryptionFileProperties();
     
    				HRESULT SetPasswordEncryptionOptions(
    					LPCTSTR pszPwdEncryProv = NULL,
    					LPCTSTR pszPwdEncryAlgo = NULL,
    					long nPwdEncryKeyLen = 0,
    					bool bPwdEncryFileProp = true);
     
    				bool GetReadOnlyRecommended();
    				void SetReadOnlyRecommended(bool bReadOnlyRecommended);
     
    				HRESULT Protect(CString strPassword, bool bSheets, bool bWindows);
    				HRESULT ProtectSharing (
    					CString strFilename, 
    					CString strPassword, 
    					CString strWriteResPassword,
    					bool bReadOnlyRecommended,
    					bool bCreateBackup,
    					CString strSharingPassword);
     
    				HRESULT Unprotect(CString strPassword);
    				HRESULT UnprotectSharing(CString strSharingPassword);
     
    			}; // class CAksWorkBook
     
    		} // namespace AksExcel
    	} // namespace Automation
    } // namespace AKS
    Voici la classe CAksWorkSheets dans son fichier AksWorkSheets.h
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
     
    #pragma once
     
    namespace AKS
    {
    	namespace Automation
    	{
    		namespace AksExcel
    		{
    			class AFX_EXT_CLASS CAksWorkSheets : public CAksComPtrT<Excel::SheetsPtr>
    			{
    				AKS_CONSTRUCT_COM_PTR_T(CAksWorkSheets, Excel::SheetsPtr)
     
    			public:
    				IDispatchPtr GetItem(long nItemIndex);
    				IDispatchPtr GetItem(CString strItemName);
     
    				CString GetWorkSheetName(long nItemIndex);
    				long GetWorkSheetIndex(CString strItemName);
     
    				long GetWorkSheetCount();
    				POSITION GetFirstWorkSheetPosition();
    				IDispatchPtr GetNextWorkSheet(POSITION& pos);
     
    			private:
    				long m_Pos;
    			}; // class CAksWorkSheets
     
    		} // namespace AksExcel
    	} // namespace Automation
    } // namespace AKS
    Voici la classe CAksWorkSheet dans son fichier AksWorkSheet.h
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
     
    #pragma once
     
    namespace AKS
    {
    	namespace Automation
    	{
    		namespace AksExcel
    		{
    			class AFX_EXT_CLASS CAksWorkSheet : public CAksComPtrT<Excel::_WorksheetPtr>
    			{
    				AKS_CONSTRUCT_COM_PTR_T(CAksWorkSheet, Excel::_WorksheetPtr)
     
    			public:
    				CString GetName(void);
    				void PutName(CString strName);
     
    				Excel::RangePtr GetRange(const CString strAddr1, const CString strAddr2);
    				Excel::RangePtr GetRange(const CString strAddr);
    				Excel::RangePtr GetRange(CAksRange spTopLeft, long nRows, long nCols);
    				Excel::RangePtr GetRange(const CString strAddr, long nRows, long nCols);
    				Excel::RangePtr GetRange(CAksRange spTopLeft, CAksRange spBottomRight);
    				Excel::RangePtr GetRange(LPCTSTR szAddr, long nRows, long nCols);
    				Excel::RangePtr GetRange(long nRowPos, long nColPos, long nRows, long nCols);
     
    			public:
    				Excel::RangePtr GetLimitRowRangeAt(long nRowPos, long nColPos);
    				Excel::RangePtr GetLimitRowRangeAt(CAksRange spTopLeft);
    				Excel::RangePtr GetLimitRowRangeAt(const CString strAddr);
    				Excel::RangePtr GetLimitRowRangeAt(CAksRange spTopLeft, long nColSize);
    				Excel::RangePtr GetLimitRowRangeAt(const CString strAddr, long nColSize);
     
    				Excel::RangePtr GetLimitColRangeAt(long nRowPos, long nColPos);
    				Excel::RangePtr GetLimitColRangeAt(CAksRange spTopLeft);
    				Excel::RangePtr GetLimitColRangeAt(const CString strAddr);
    				Excel::RangePtr GetLimitColRangeAt(CAksRange spTopLeft, long nRowSize);
    				Excel::RangePtr GetLimitColRangeAt(const CString strAddr, long nRowSize);
     
    				Excel::RangePtr GetLimitRangeAt(long nRowPos, long nColPos);
    				Excel::RangePtr GetLimitRangeAt(CAksRange spTopLeft);
    				Excel::RangePtr GetLimitRangeAt(const CString strAddr);
     
    			public:
    				long GetTotalRowCount();
    				long GetTotalColCount();
     
    				CAksWorkSheet GetPreviousSheet();
    				CAksWorkSheet GetNextSheet();
     
    				long GetSheetIndex();
    				HRESULT MoveSheet(CAksWorkSheet spBefore, CAksWorkSheet spAfter);
     
    				HRESULT SaveAs(
    					CString strXlFile, 
    					CString strPassword, 
    					CString strWriteResPassword, 
    					bool bReadOnly = false);
     
    				void CopyRange(CAksRange spSource, CAksRange spDestination);
     
    				CAksRange ResearchV(const CString strVal, CAksRange spCol, bool bAddBottom = false);
    				CAksRange ResearchV(const CString strVal, const CString strAddr1, const CString strAddr2, bool bAddBottom = false);
    				CAksRange ResearchV(const CString strVal, const CString strAddr, long nRowSize, bool bAddBottom = false);
    				CAksRange ResearchV(const CString strVal, const CString strAddr, bool bAddBottom = false);
     
    				CAksRange ResearchH(const CString strVal, CAksRange spRow, bool bAddRight = false);
    				CAksRange ResearchH(const CString strVal, const CString strAddr1, const CString strAddr2, bool bAddRight = false);
    				CAksRange ResearchH(const CString strVal, const CString strAddr, long nColSize, bool bAddRight = false);
    				CAksRange ResearchH(const CString strVal, const CString strAddr, bool bAddRight = false);
     
    				CAksRange MultiResearchV(
    					AKS::Utility::CAksVariantArray& arValues,
    					AKS::Utility::CAksVariantArray& arOffsetCols,
    					CAksRange spRefCol,
    					bool bAddBottom = false,
    					bool bIncludeEmpty = true);
     
    				CAksRange MultiResearchV(
    					AKS::Utility::CAksVariantArray& arValues,
    					AKS::Utility::CAksVariantArray& arOffsetCols,
    					const CString strAddr1, 
    					const CString strAddr2,
    					bool bAddBottom = false,
    					bool bIncludeEmpty = true);
     
    				CAksRange MultiResearchV(
    					AKS::Utility::CAksVariantArray& arValues,
    					AKS::Utility::CAksVariantArray& arOffsetCols,
    					const CString strAddr, 
    					long nRowSize,
    					bool bAddBottom = false,
    					bool bIncludeEmpty = true);
     
    				CAksRange MultiResearchV(
    					AKS::Utility::CAksVariantArray& arValues,
    					AKS::Utility::CAksVariantArray& arOffsetCols,
    					const CString strAddr,
    					bool bAddBottom = false,
    					bool bIncludeEmpty = true);
     
    				CAksRange MultiResearchH(
    					AKS::Utility::CAksVariantArray& arValues,
    					AKS::Utility::CAksVariantArray& arOffsetRows,
    					CAksRange spRefRow,
    					bool bAddRight = false,
    					bool bIncludeEmpty = true);
     
    				CAksRange MultiResearchH(
    					AKS::Utility::CAksVariantArray& arValues,
    					AKS::Utility::CAksVariantArray& arOffsetRows,
    					const CString strAddr1, 
    					const CString strAddr2,
    					bool bAddRight = false,
    					bool bIncludeEmpty = true);
     
    				CAksRange MultiResearchH(
    					AKS::Utility::CAksVariantArray& arValues,
    					AKS::Utility::CAksVariantArray& arOffsetRows,
    					const CString strAddr,
    					long nColSize,
    					bool bAddRight = false,
    					bool bIncludeEmpty = true);
     
    				CAksRange MultiResearchH(
    					AKS::Utility::CAksVariantArray& arValues,
    					AKS::Utility::CAksVariantArray& arOffsetRows,
    					const CString strAddr,
    					bool bAddRight = false,
    					bool bIncludeEmpty = true);
     
    			public:
    				CAksRange LoadSheetHeader(const CString strAddr, const CHeaderCtrl* pHeaderCtrl);
    				CAksRange LoadSheetHeader(long nRowPos, long nColPos, const CHeaderCtrl* pHeaderCtrl);
    				CAksRange LoadSheetHeader(CAksRange spTopLeft, const CHeaderCtrl* pHeaderCtrl);
     
    				CAksRange LoadSheet(const CString strAddr, const CListCtrl& rListCtrl, bool bIncludeHeader = true);
    				CAksRange LoadSheet(long nRowPos, long nColPos, const CListCtrl& rListCtrl, bool bIncludeHeader = true);
    				CAksRange LoadSheet(CAksRange spTopLeft, const CListCtrl& rListCtrl, bool bIncludeHeader = true);
     
    				CAksRange LoadHeader(long nRowPos, long nColPos, long nRows, long nCols, CListCtrl& rListCtrl);
    				CAksRange LoadHeader(const CString strAddr, long nRows, long nCols, CListCtrl& rListCtrl);
    				CAksRange LoadHeader(CAksRange spTopLeft, CAksRange spBottomRight, CListCtrl& rListCtrl);
    				CAksRange LoadHeader(CAksRange spHeader, CListCtrl& rListCtrl, bool bAutoColumnText = false);
     
    				CAksRange LoadList(long nRowPos, long nColPos, long nRows, long nCols, CListCtrl& rListCtrl, bool bIncludeHeader = true);
    				CAksRange LoadList(const CString strAddr, long nRows, long nCols, CListCtrl& rListCtrl, bool bIncludeHeader = true);
    				CAksRange LoadList(CAksRange spTopLeft, CAksRange spBottomRight, CListCtrl& rListCtrl, bool bIncludeHeader = true);
    				CAksRange LoadList(CAksRange spList, CListCtrl& rListCtrl, bool bIncludeHeader = true);
     
    			}; // class CAksWorkSheet
     
    		} // namespace AksExcel
    	} // namespace Automation
    } // namespace AKS
    Voici la classe CAksRange dans son fichier AksRange.h
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
     
    #pragma once
     
    namespace AKS
    {
    	namespace Automation
    	{
    		namespace AksExcel
    		{
    			class AFX_EXT_CLASS CAksRange : public CAksComPtrT<Excel::RangePtr>
    			{
    				AKS_CONSTRUCT_COM_PTR_T(CAksRange, Excel::RangePtr)
     
    			public:
    				// Geometric methods
    				long GetRowPosition();
    				long GetColPosition();
     
    				long GetRowCount();
    				long GetColCount();
     
    				void PutValue(AKS::CAksVariant value);
    				AKS::CAksVariant GetValue();
     
    				CAksRange GetCellAt(long nRow, long nCol);
    				CAksRange GetOffsetCellAt(long nRow, long nCol, long nOffsetRow, long nOffsetCol);
     
    				AKS::CAksVariant GetItem(long nRow, long nCol);
    				void PutItem(long nRow, long nCol, AKS::CAksVariant value);
     
    				AKS::CAksVariant GetOffsetItem(long nRow, long nCol, long nOffsetRow, long nOffsetCol);
    				void PutOffsetItem(long nRow, long nCol, long nOffsetRow, long nOffsetCol, AKS::CAksVariant value);
     
    				CString GetLocalAddress();
    				CString GetLocalAddress(long nRow, long nCol);
    				CString GetOffsetLocalAddress(long nRow, long nCol, long nOffsetRow, long nOffsetCol);
     
    				CAksRange GetTopLeft();
    				CAksRange GetTopRight();
    				CAksRange GetBottomLeft();
    				CAksRange GetBottomRight();
     
    				CAksRange GetRowAt(long nRow);
    				CAksRange GetColAt(long nCol);
     
    				CAksRange GetOffsetRowAt(long nOffsetRow = 0);
    				CAksRange GetOffsetColAt(long nOffsetCol = 0);
     
    				CAksRange GetSubRangeAt(long nRowPos, long nColPos, long nRows, long nCols);
     
    				CAksRange AddTopRow();
    				CAksRange AddBottomRow();
    				CAksRange AddLeftColumn();
    				CAksRange AddRightColumn();
     
    				bool RemoveTopRow();
    				bool RemoveBottomRow();
    				bool RemoveLeftColumn();
    				bool RemoveRightColumn();
     
    				bool AutoResize(long nRows, long nCols);
    				bool Move(long nOffsetRow, long nOffsetCol);
     
    				CAksRange GetTopRow();
    				CAksRange GetBottomRow();
    				CAksRange GetLeftColumn();
    				CAksRange GetRightColumn();
     
    				int GetColumnWidth();
    				void SetColumnWidth(int nWidth);
     
    				int GetColumnWidth(long nRow, long nCol);
    				void SetColumnWidth(long nRow, long nCol, int nWidth);
     
    				int GetRowHeight();
    				void SetRowHeight(int nHeight);
     
    				int GetRowHeight(long nRow, long nCol);
    				void SetRowHeight(long nRow, long nCol, int nHeight);
     
    				bool HasMergeCells();
    				void PutMergeCells(bool bMerge);
     
    				CAksRange GetMergeArea();
     
    				bool Merge(bool bByRow = false);
    				bool UnMerge();
     
    				// Style methods
    			public:
    				void PutBordersLineStyle(Excel::XlLineStyle arg1);
    				void PutBordersGrid(Excel::XlLineStyle arg1);
    				void PutWeight(Excel::XlBorderWeight arg1);
     
    				void PutBold(BOOL bBold);
    				void PutSize(short nSize);
     
    				void SetHorizAlign(Excel::XlHAlign align);
    				Excel::XlHAlign GetHorizAlign();
     
    				void SetVertAlign(Excel::XlVAlign align);
    				Excel::XlVAlign GetVertAlign();
     
    				void PutColorIndex(short nIndex);
    				void SetColor(COLORREF color);
    				COLORREF GetColor();
     
    				void SetNumberFormat(CString strNumberFormat);
    				CString GetNumberFormat();
     
    				bool IsTextWraped();
    				void WrapText(bool bWrap);
     
    				// Operation methods
    			public:
    				void PutFormula(CString strFormula);
    				CString GetFormula();
     
    				void PutColumnSumFormula(CAksRange spCols);
    				void PutRowSumFormula(CAksRange spRows);
     
    				void PutColumnMoyFormula(CAksRange spCols);
    				void PutRowMoyFormula(CAksRange spRows);
     
    				void PutColumnFormula(CAksRange spCols, CString strFormula);
    				void PutRowFormula(CAksRange spRows, CString strFormula);
     
    				AKS::CAksVariant AutoFitColumns();
    				AKS::CAksVariant AutoFitRows();
     
    				void FindData(AKS::CAksVariant Data, long& nRowFound, long& nColFound);
    				CAksRange FindRowRange(CString strData, long nFoundAtCol);
    				CAksRange FindColRange(CString strData, long nFoundAtRow);
     
    				bool Sort(short XlSortOrientation, short XlSortOrder, long nOrientationIndex = 1, VARTYPE vt = VT_BSTR);
    				bool SortCols(short XlSortOrder, long nRowIndex = 1, VARTYPE vt = VT_BSTR);
    				bool SortRows(short XlSortOrder, long nColIndex = 1, VARTYPE vt = VT_BSTR);
     
    				AKS::CAksVariant Clear();
    				AKS::CAksVariant ClearContents();
     
    				Excel::RangePtr PutHorizontalArrayValues(AKS::Utility::CAksSafeArray& safeArray);
    				Excel::RangePtr PutVerticalArrayValues(AKS::Utility::CAksSafeArray& safeArray);
    				Excel::RangePtr PutMatrixValues(AKS::Utility::CAksSafeArray& safeArray);
     
    				Excel::RangePtr PutHorizontalArrayDataSet(AKS::CAksDataSet& dsArray);
    				Excel::RangePtr PutHorizontalArrayDataSet(LPSTR* pszRowData, long dwLen);
    				Excel::RangePtr GetHorizontalArrayDataSet(long nCols, AKS::CAksDataSet& dsArray, VARTYPE vt = VT_BSTR);
     
    				Excel::RangePtr PutVerticalArrayDataSet(AKS::CAksDataSet& dsArray);
    				Excel::RangePtr PutVerticalArrayDataSet(LPSTR* pszColData, long dwLen);
    				Excel::RangePtr GetVerticalArrayDataSet(long nRows, AKS::CAksDataSet& dsArray, VARTYPE vt = VT_BSTR);
     
    				Excel::RangePtr PutMatrixDataSet(long nRowBound, long nColBound, AKS::CAksDataSet& dsMatrix);
    				Excel::RangePtr GetMatrixDataSet(long nRowBound, long nColBound, AKS::CAksDataSet& dsMatrix, VARTYPE vt = VT_BSTR);
     
    				Excel::RangePtr PutHorizontalArray(AKS::Utility::CAksVariantArray& VariantArray);
    				Excel::RangePtr PutVerticalArray(AKS::Utility::CAksVariantArray& VariantArray);
    				Excel::RangePtr GetHorizontalArray(AKS::Utility::CAksVariantArray& VariantArray);
    				Excel::RangePtr GetVerticalArray(AKS::Utility::CAksVariantArray& VariantArray);
     
    				void CopyRange(CAksRange spSource);
     
    			}; // class CAksRange
     
    		} // namespace AksExcel
    	} // namespace Automation
    } // namespace AKS
    Il manque encore 2 ou 3 petites classes utilitaires mais prend d'abord ces fichiers en-têtes

  15. #15
    Membre confirmé
    Inscrit en
    Novembre 2010
    Messages
    176
    Détails du profil
    Informations forums :
    Inscription : Novembre 2010
    Messages : 176
    Par défaut yep !
    çà ya est. c'est tout bien ordonné dans des fichiers *.h
    çà devient sérieux .....

  16. #16
    Membre émérite
    Avatar de Gabrielly
    Inscrit en
    Juin 2004
    Messages
    722
    Détails du profil
    Informations forums :
    Inscription : Juin 2004
    Messages : 722
    Par défaut
    Citation Envoyé par tallent_e
    çà ya est. c'est tout bien ordonné dans des fichiers *.h
    çà devient sérieux .....
    Yep,
    Lorsque tu prendra de cette eau tu n'aurras plus jamais soif mais de ton sein coulerons des sources d'eaux vives
    Ce thread que nous contruisons sera bénifiques pour plusieurs.

    Récupère aussi quelques 3 classes utilitaires

    comme CAksVariantArray dans son fichier AksVariantArray.h
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
     
    #pragma once
     
    #include <afxtempl.h>
     
    // CAksArray command target
    namespace AKS
    {
    	namespace Utility
    	{
     
    		class AFX_EXT_CLASS CAksVariantArray: public CArray<CAksVariant, CAksVariant>
    		{
    		public:
    			CAksVariantArray()
    			{
    				m_vtOperation = VT_BSTR;
    			}
     
    			INT_PTR WriteDateSet(AKS::CAksDataSet& dsArray)
    			{
    				dsArray.Reset();
    				INT_PTR nCount = GetCount();
    				INT_PTR nIndex = 0;
    				while(nIndex < nCount)
    				{
    					CAksVariant Value = GetAt(nIndex);
    					Value.m_vtOperation = m_vtOperation;
    					dsArray.AddVariant((long)nIndex++, Value);
    				}
    				return nIndex;
    			}
     
    			INT_PTR ReadDataSet(AKS::CAksDataSet& dsArray)
    			{
    				RemoveAll();
    				POSITION pos = dsArray.GetFirstPosition();
    				INT_PTR nIndex = 0;
    				while(pos)
    				{
    					CStringA strKey;
    					CStringA strValue;
    					dsArray.GetNext(pos, strKey, strValue);
    					m_vtOperation = VT_BSTR;
    					SetAtGrow(nIndex++, strValue);
    				}
    				return nIndex;
    			}
     
    		public:
    			VARTYPE m_vtOperation;
    		};
    	} // namespace Utility
    } // namespace AKS
    comme CAksSafeArray dans son fichier AksSafeArray.h
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
     
    #pragma once
     
    #include <afxdisp.h>
     
    // CAksSafeArray command target
    namespace AKS
    {
    	namespace Utility
    	{
    		class AFX_EXT_CLASS CAksSafeArray: public COleSafeArray
    		{
    			//Constructors
    		public:
    			CAksSafeArray();
    			CAksSafeArray(const SAFEARRAY& saSrc, VARTYPE vtSrc);
    			CAksSafeArray(LPCSAFEARRAY pSrc, VARTYPE vtSrc);
    			CAksSafeArray(const COleSafeArray& saSrc);
    			CAksSafeArray(const CAksSafeArray& saSrc);
    			CAksSafeArray(const VARIANT& varSrc);
    			CAksSafeArray(LPCVARIANT pSrc);
    			CAksSafeArray(const COleVariant& varSrc);
     
    			void FillSafeArray(long nIndex, CStringA str);
    			void FillSafeArray(long nIndex, long nValue);
    			void FillSafeArray(long nIndex, double dValue);
     
    			void FillSafeMatrix(long iRow, long iCol, CStringA str);
    			void FillSafeMatrix(long iRow, long iCol, long nValue);
    			void FillSafeMatrix(long iRow, long iCol, double dValue);
     
    			void FillSafeCube(long iRow, long iCol, long iHeight, CStringA str);
    			void FillSafeCube(long iRow, long iCol, long iHeight, long nValue);
    			void FillSafeCube(long iRow, long iCol, long iHeight, double dValue);
     
    			void FillSafeArray(AKS::CAksDataSet dsValueSet);
    			void FillSafeArrayValues(AKS::CAksDataSet dsValueSet);
    			void FillSafeArrayKeys(AKS::CAksDataSet dsKeySet);
    			void FillSafeMatrix(AKS::CAksDataSet dsValueSet);
    			void FillSafeCube(AKS::CAksDataSet dsValueSet);
    		};
     
    	} // namespace Utility
    } // namespace AKS
    et ...

  17. #17
    Membre émérite
    Avatar de Gabrielly
    Inscrit en
    Juin 2004
    Messages
    722
    Détails du profil
    Informations forums :
    Inscription : Juin 2004
    Messages : 722
    Par défaut
    comme CAksDataSet dans son fichier AksDataSet.h
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
    422
    423
    424
    425
    426
    427
    428
    429
    430
    431
    432
    433
    434
    435
    436
    437
    438
    439
    440
    441
    442
    443
    444
    445
    446
    447
    448
    449
    450
    451
    452
    453
    454
    455
    456
    457
    458
    459
    460
    461
    462
    463
    464
    465
    466
    467
    468
    469
    470
    471
    472
    473
    474
    475
    476
    477
    478
    479
    480
    481
    482
    483
    484
    485
    486
    487
    488
    489
    490
    491
    492
    493
    494
    495
    496
    497
    498
    499
    500
    501
    502
    503
    504
    505
    506
    507
    508
    509
    510
    511
    512
    513
    514
    515
    516
    517
    518
    519
    520
    521
    522
    523
    524
    525
    526
    527
    528
    529
    530
    531
    532
    533
    534
    535
    536
    537
    538
    539
    540
    541
    542
    543
    544
    545
    546
    547
    548
    549
    550
    551
    552
    553
    554
    555
    556
    557
    558
    559
    560
    561
    562
    563
    564
    565
    566
    567
    568
    569
    570
    571
    572
    573
    574
    575
    576
    577
    578
    579
    580
    581
    582
    583
    584
    585
    586
    587
    588
    589
    590
    591
    592
    593
    594
    595
    596
    597
    598
    599
    600
    601
    602
    603
    604
    605
    606
    607
    608
    609
    610
    611
    612
    613
    614
    615
    616
    617
    618
    619
    620
    621
    622
    623
    624
    625
    626
    627
    628
    629
    630
    631
    632
    633
    634
    635
    636
    637
    638
    639
    640
    641
    642
    643
    644
    645
    646
    647
    648
    649
    650
    651
    652
    653
    654
    655
    656
    657
    658
    659
    660
    661
    662
    663
    664
    665
    666
    667
    668
    669
    670
    671
    672
    673
    674
    675
    676
    677
    678
    679
    680
    681
    682
    683
    684
    685
    686
    687
    688
    689
    690
    691
    692
    693
    694
    695
    696
    697
    698
    699
    700
    701
    702
    703
    704
    705
    706
    707
    708
    709
    710
    711
    712
    713
    714
    715
    716
    717
    718
    719
    720
    721
    722
    723
    724
    725
    726
    727
    728
    729
    730
    731
    732
    733
    734
    735
    736
    737
    738
    739
    740
    741
    742
    743
    744
    745
    746
    747
    748
    749
    750
    751
    752
    753
    754
    755
    756
    757
    758
    759
    760
    761
    762
    763
    764
    765
    766
    767
    768
    769
    770
    771
    772
    773
    774
    775
    776
    777
    778
    779
    780
    781
    782
    783
    784
    785
    786
    787
    788
    789
    790
    791
    792
    793
    794
    795
    796
    797
    798
    799
    800
    801
    802
    803
    804
    805
    806
    807
    808
    809
    810
    811
    812
    813
    814
    815
    816
    817
    818
    819
    820
    821
    822
    823
    824
    825
    826
    827
    828
    829
    830
    831
    832
    833
    834
    835
    836
    837
    838
    839
    840
    841
    842
    843
    844
    845
    846
    847
    848
    849
    850
    851
    852
    853
    854
    855
    856
    857
    858
    859
    860
    861
    862
    863
    864
    865
    866
    867
    868
    869
    870
    871
    872
    873
    874
    875
    876
    877
    878
    879
    880
    881
    882
    883
    884
    885
    886
    887
    888
    889
    890
    891
    892
    893
    894
    895
    896
    897
    898
    899
    900
    901
    902
    903
    904
    905
    906
    907
    908
    909
    910
    911
    912
    913
    914
    915
    916
    917
    918
    919
    920
    921
    922
    923
    924
    925
    926
    927
    928
    929
    930
    931
    932
    933
    934
    935
    936
    937
    938
    939
    940
    941
    942
    943
    944
    945
    946
    947
    948
    949
    950
    951
    952
    953
    954
    955
    956
    957
    958
    959
    960
    961
    962
    963
    964
    965
    966
    967
    968
    969
    970
    971
    972
    973
    974
    975
    976
    977
    978
    979
    980
    981
    982
    983
    984
    985
    986
    987
    988
    989
    990
    991
    992
    993
    994
    995
    996
    997
    998
    999
    1000
    1001
    1002
    1003
    1004
    1005
    1006
    1007
    1008
    1009
    1010
    1011
    1012
    1013
    1014
    1015
    1016
    1017
    1018
    1019
    1020
    1021
    1022
    1023
    1024
    1025
    1026
    1027
    1028
    1029
    1030
    1031
    1032
    1033
    1034
    1035
    1036
    1037
    1038
    1039
    1040
    1041
    1042
    1043
    1044
    1045
    1046
    1047
    1048
    1049
    1050
    1051
    1052
    1053
    1054
    1055
    1056
    1057
    1058
    1059
    1060
    1061
    1062
    1063
    1064
    1065
    1066
    1067
    1068
    1069
    1070
    1071
    1072
    1073
    1074
    1075
    1076
    1077
    1078
    1079
    1080
    1081
    1082
    1083
    1084
    1085
    1086
    1087
    1088
    1089
    1090
    1091
    1092
    1093
    1094
    1095
    1096
    1097
    1098
    1099
    1100
    1101
    1102
    1103
    1104
    1105
    1106
    1107
    1108
    1109
    1110
    1111
    1112
    1113
    1114
    1115
    1116
    1117
    1118
    1119
    1120
    1121
    1122
    1123
    1124
    1125
    1126
    1127
    1128
    1129
    1130
    1131
    1132
    1133
    1134
    1135
    1136
    1137
    1138
    1139
    1140
    1141
    1142
    1143
    1144
    1145
    1146
    1147
    1148
    1149
    1150
    1151
    1152
    1153
    1154
    1155
    1156
    1157
    1158
    1159
    1160
    1161
    1162
    1163
    1164
    1165
    1166
    1167
    1168
    1169
    1170
    1171
    1172
    1173
    1174
    1175
    1176
    1177
    1178
    1179
    1180
    1181
    1182
    1183
    1184
    1185
    1186
    1187
    1188
    1189
    1190
    1191
    1192
    1193
    1194
    1195
    1196
    1197
    1198
    1199
    1200
    1201
    1202
    1203
    1204
    1205
    1206
    1207
    1208
    1209
    1210
    1211
    1212
    1213
    1214
    1215
    1216
    1217
    1218
    1219
    1220
    1221
    1222
    1223
    1224
    1225
    1226
    1227
    1228
    1229
    1230
    1231
    1232
    1233
    1234
    1235
    1236
    1237
    1238
    1239
    1240
    1241
    1242
    1243
    1244
    1245
    1246
    1247
    1248
    1249
    1250
    1251
    1252
    1253
    1254
    1255
    1256
    1257
    1258
    1259
    1260
    1261
    1262
    1263
    1264
    1265
    1266
    1267
    1268
    1269
    1270
    1271
    1272
    1273
    1274
    1275
    1276
    1277
    1278
    1279
    1280
    1281
    1282
    1283
    1284
    1285
    1286
    1287
    1288
    1289
    1290
    1291
    1292
    1293
    1294
    1295
    1296
    1297
    1298
    1299
    1300
    1301
    1302
    1303
    1304
    1305
    1306
    1307
    1308
    1309
    1310
    1311
    1312
    1313
    1314
    1315
    1316
    1317
    1318
    1319
    1320
    1321
    1322
    1323
    1324
    1325
    1326
    1327
    1328
    1329
    1330
    1331
    1332
    1333
    1334
    1335
    1336
    1337
    1338
    1339
    1340
    1341
    1342
    1343
    1344
    1345
    1346
    1347
    1348
    1349
    1350
    1351
    1352
    1353
    1354
    1355
    1356
    1357
    1358
    1359
    1360
    1361
    1362
    1363
    1364
    1365
    1366
    1367
    1368
    1369
    1370
    1371
    1372
    1373
    1374
    1375
    1376
    1377
    1378
    1379
    1380
    1381
    1382
    1383
    1384
    1385
    1386
    1387
    1388
    1389
    1390
    1391
    1392
    1393
    1394
    1395
    1396
    1397
    1398
    1399
    1400
    1401
    1402
    1403
    1404
    1405
    1406
    1407
    1408
    1409
    1410
    1411
    1412
    1413
    1414
    1415
    1416
    1417
    1418
    1419
    1420
    1421
    1422
    1423
    1424
    1425
    1426
    1427
    1428
    1429
    1430
    1431
    1432
    1433
    1434
    1435
    1436
    1437
    1438
    1439
    1440
    1441
    1442
    1443
    1444
    1445
    1446
    1447
    1448
    1449
    1450
    1451
    1452
    1453
    1454
    1455
    1456
    1457
    1458
    1459
    1460
    1461
    1462
    1463
    1464
    1465
    1466
    1467
    1468
    1469
    1470
    1471
    1472
    1473
    1474
    1475
    1476
    1477
    1478
    1479
    1480
    1481
    1482
    1483
    1484
    1485
    1486
    1487
    1488
    1489
    1490
    1491
    1492
    1493
    1494
    1495
    1496
    1497
    1498
    1499
    1500
    1501
    1502
    1503
    1504
    1505
    1506
    1507
    1508
    1509
    1510
    1511
    1512
    1513
    1514
    1515
    1516
    1517
    1518
    1519
    1520
    1521
    1522
    1523
    1524
    1525
    1526
    1527
    1528
    1529
    1530
    1531
    1532
    1533
    1534
    1535
    1536
    1537
    1538
    1539
    1540
    1541
    1542
    1543
    1544
    1545
    1546
    1547
    1548
    1549
    1550
    1551
    1552
    1553
    1554
    1555
    1556
    1557
    1558
    1559
    1560
    1561
    1562
    1563
    1564
    1565
    1566
    1567
    1568
    1569
    1570
    1571
    1572
    1573
    1574
    1575
    1576
    1577
    1578
    1579
    1580
    1581
    1582
    1583
    1584
    1585
    1586
    1587
    1588
    1589
    1590
    1591
    1592
    1593
    1594
    1595
    1596
    1597
    1598
    1599
    1600
    1601
    1602
    1603
    1604
    1605
    1606
    1607
    1608
    1609
    1610
    1611
    1612
    1613
    1614
    1615
    1616
    1617
    1618
    1619
    1620
    1621
    1622
    1623
    1624
    1625
    1626
    1627
    1628
    1629
    1630
    1631
    1632
    1633
    1634
    1635
    1636
    1637
    1638
    1639
    1640
    1641
    1642
    1643
    1644
    1645
    1646
    1647
    1648
    1649
    1650
    1651
    1652
    1653
    1654
    1655
    1656
    1657
    1658
    1659
    1660
    1661
    1662
    1663
    1664
    1665
    1666
    1667
    1668
    1669
    1670
    1671
    1672
    1673
    1674
    1675
    1676
    1677
    1678
    1679
    1680
    1681
    1682
    1683
    1684
    1685
    1686
    1687
    1688
    1689
    1690
    1691
    1692
    1693
    1694
    1695
    1696
    1697
    1698
    1699
    1700
    1701
    1702
    1703
    1704
    1705
    1706
    1707
    1708
    1709
    1710
    1711
    1712
    1713
    1714
    1715
    1716
    1717
    1718
    1719
    1720
    1721
    1722
    1723
    1724
    1725
    1726
    1727
    1728
    1729
    1730
    1731
    1732
    1733
    1734
    1735
    1736
    1737
    1738
    1739
    1740
    1741
    1742
    1743
    1744
    1745
    1746
    1747
    1748
    1749
    1750
    1751
    1752
    1753
    1754
    1755
    1756
    1757
    1758
    1759
    1760
    1761
    1762
    1763
    1764
    1765
    1766
    1767
    1768
    1769
    1770
    1771
    1772
    1773
    1774
    1775
    1776
    1777
    1778
    1779
    1780
    1781
    1782
    1783
    1784
    1785
    1786
    1787
    1788
    1789
    1790
    1791
    1792
    1793
    1794
    1795
    1796
    1797
    1798
    1799
    1800
    1801
    1802
    1803
    1804
    1805
    1806
    1807
    1808
    1809
    1810
    1811
    1812
    1813
    1814
    1815
    1816
    1817
    1818
    1819
    1820
    1821
    1822
    1823
    1824
    1825
    1826
    1827
    1828
    1829
    1830
    1831
    1832
    1833
    1834
    1835
    1836
    1837
    1838
    1839
    1840
    1841
    1842
    1843
    1844
    1845
    1846
    1847
    1848
    1849
    1850
    1851
    1852
    1853
    1854
    1855
    1856
    1857
    1858
    1859
    1860
    1861
    1862
    1863
    1864
    1865
    1866
    1867
    1868
    1869
    1870
    1871
    1872
    1873
    1874
    1875
    1876
    1877
    1878
    1879
    1880
    1881
    1882
    1883
    1884
    1885
    1886
    1887
    1888
    1889
    1890
    1891
    1892
    1893
    1894
    1895
    1896
    1897
    1898
    1899
    1900
    1901
    1902
    1903
    1904
    1905
    1906
    1907
    1908
    1909
    1910
    1911
    1912
    1913
    1914
    1915
    1916
    1917
    1918
    1919
    1920
    1921
    1922
    1923
    1924
    1925
    1926
    1927
    1928
    1929
    1930
    1931
    1932
    1933
    1934
    1935
    1936
    1937
    1938
    1939
    1940
    1941
    1942
    1943
    1944
    1945
    1946
    1947
    1948
    1949
    1950
    1951
    1952
    1953
    1954
    1955
    1956
    1957
    1958
    1959
    1960
    1961
    1962
    1963
    1964
    1965
    1966
    1967
    1968
    1969
    1970
    1971
    1972
    1973
    1974
    1975
    1976
    1977
    1978
    1979
    1980
    1981
    1982
    1983
    1984
    1985
    1986
    1987
    1988
    1989
    1990
    1991
    1992
    1993
    1994
    1995
    1996
    1997
    1998
    1999
    2000
    2001
    2002
    2003
    2004
    2005
    2006
    2007
    2008
    2009
    2010
    2011
    2012
    2013
    2014
    2015
    2016
    2017
    2018
    2019
    2020
    2021
    2022
    2023
    2024
    2025
    2026
    2027
    2028
    2029
    2030
    2031
    2032
    2033
    2034
    2035
    2036
    2037
    2038
    2039
    2040
    2041
    2042
    2043
    2044
    2045
    2046
    2047
    2048
    2049
    2050
    2051
    2052
    2053
    2054
    2055
    2056
    2057
    2058
    2059
    2060
    2061
    2062
    2063
    2064
    2065
    2066
    2067
    2068
    2069
    2070
    2071
    2072
    2073
    2074
    2075
    2076
    2077
    2078
    2079
    2080
    2081
    2082
    2083
    2084
    2085
    2086
    2087
    2088
    2089
    2090
    2091
    2092
    2093
    2094
    2095
    2096
    2097
    2098
    2099
    2100
    2101
    2102
    2103
    2104
    2105
    2106
    2107
    2108
    2109
    2110
    2111
    2112
    2113
    2114
    2115
    2116
    2117
    2118
    2119
    2120
    2121
    2122
    2123
    2124
    2125
    2126
    2127
    2128
    2129
    2130
    2131
    2132
    2133
    2134
    2135
    2136
    2137
    2138
    2139
    2140
    2141
    2142
    2143
    2144
    2145
    2146
    2147
    2148
    2149
    2150
    2151
    2152
    2153
    2154
    2155
    2156
    2157
    2158
    2159
    2160
    2161
    2162
    2163
    2164
    2165
    2166
    2167
    2168
    2169
    2170
    2171
    2172
    2173
    2174
    2175
    2176
    2177
    2178
    2179
    2180
    2181
    2182
    2183
    2184
    2185
    2186
    2187
    2188
    2189
    2190
    2191
    2192
    2193
    2194
    2195
    2196
    2197
    2198
    2199
    2200
    2201
    2202
    2203
    2204
    2205
    2206
    2207
    2208
    2209
    2210
    2211
    2212
    2213
    2214
    2215
    2216
    2217
    2218
    2219
    2220
    2221
    2222
    2223
    2224
     
    #pragma once
     
    #include <atlcoll.h>
    #include <atlutil.h>
     
    #ifndef ATL_EPSILON
    	#define ATL_EPSILON .0001
    #endif
     
    #ifndef VALIDATION_S_OK
    	#define VALIDATION_S_OK				0x00000000
    #endif
     
    #ifndef VALIDATION_S_EMPTY
    	#define VALIDATION_S_EMPTY			0x00000001
    #endif
     
    #ifndef VALIDATION_E_PARAMNOTFOUND
    	#define VALIDATION_E_PARAMNOTFOUND	0x00000002
    #endif
     
    #ifndef VALIDATION_E_LENGTHMIN
    	#define VALIDATION_E_LENGTHMIN		0x80000083
    #endif
     
    #ifndef VALIDATION_E_LENGTHMAX
    	#define VALIDATION_E_LENGTHMAX		0x80000084
    #endif
     
    #ifndef VALIDATION_E_INVALIDLENGTH
    	#define VALIDATION_E_INVALIDLENGTH  0x80000080
    #endif
     
    #ifndef VALIDATION_E_INVALIDPARAM
    	#define VALIDATION_E_INVALIDPARAM	0x80000005
    #endif
     
    #ifndef VALIDATION_E_FAIL
    	#define VALIDATION_E_FAIL			0x80000006
    #endif
     
    #ifndef VALIDATION_SUCCEEDED
    	#define VALIDATION_SUCCEEDED(x) (((x == VALIDATION_S_OK) || (x == VALIDATION_S_EMPTY )))
    #endif
     
    namespace AKS
    {
    /* 
    CAksDataSet dispose des méthodes de stockage des données instantanées telles que les AddValue().
    et propose plusieurs méthodes surchargées de validation de données instantanées telles que les Validate(). 
    Elle comprend également des méthodes d'échanges des données 
    dans leurs types primitifs sans validation telles que les Exchange(). 
    CAksDataSet propose aussi plusieurs méthodes de conversion
    des données en nombre telles que les ConvertNumber().
     
    CAksDataSet fournit des opérations élémentaires sur les ensembles de données
    prise dans leurs globalité en surchargeant les opérateurs +, -, +=, -=, &, &=, ^, ^=.
    Ce qui permet de faire l'union ou l'intersection de deux dataset ou retrancher un dataset d'un autre.
    Ou bien CAksDataSet permet de cumuler plusieurs ensembles de données...
    */
     
    // This class represents a collection of validation failures.
    // Use this class in combination with CValidateObject to validate
    // forms, cookies, or query strings and build up a collection of
    // failures. If appropriate, use the information in the collection
    // to return detailed responses to the client to help them correct the failures.
     
     
    class CAksValidateContext 
    {
    public:
    	enum { ATL_EMPTY_PARAMS_ARE_FAILURES = 0x00000001 };
     
    	class CAksValidateContext (__in DWORD dwFlags=0) throw()
    	{
    		m_bFailures = false;
    		m_dwFlags = dwFlags;
    	}
     
    	bool SetResultAt(__in LPCSTR szName, __in DWORD type)
    	{
    		_ATLTRY
    		{
    			if (!VALIDATION_SUCCEEDED(type) ||
    				(type == VALIDATION_S_EMPTY && (m_dwFlags & ATL_EMPTY_PARAMS_ARE_FAILURES)))
    				m_bFailures = true;
     
    			return TRUE == m_results.SetAt(szName,type);
     
    		}
    		_ATLCATCHALL()
    		{
    		}
     
    		return false;
    	}
     
    	// Call this function to add a validation result to the collection managed by this object.
    	// Each result is identified by a name and the type of result that occurred.
    	// The result codes are the VALIDATION_ codes defined at the top of this file.
    	// The bOnlyFailure parameter below is used to only allow failure results to
    	// be added to the list of failures. The reason you'd want to do this is that
    	// success codes should be the common case in validation routines so you can
    	// use bOnlyFailures to limit the number of allocations by this class's base
    	// map for mapping success results if you don't care about iterating successes.
     
    	bool AddResult(__in LPCSTR szName, __in DWORD type, __in bool bOnlyFailures = true) throw()
    	{
    		_ATLTRY
    		{
    			if (!VALIDATION_SUCCEEDED(type) ||
    				(type == VALIDATION_S_EMPTY && (m_dwFlags & ATL_EMPTY_PARAMS_ARE_FAILURES)))
    				m_bFailures = true;
     
    			if (!bOnlyFailures)
    				return TRUE == m_results.Add(szName, type); // add everything
     
    			else if (bOnlyFailures && 
    					(!VALIDATION_SUCCEEDED(type) ||
    					(type == VALIDATION_S_EMPTY && (m_dwFlags & ATL_EMPTY_PARAMS_ARE_FAILURES))))
    				return TRUE == m_results.Add(szName, type); // only add failures
    		}
    		_ATLCATCHALL()
    		{
    		}
     
    		return false;
    	}
     
    	// Returns true if there are no validation failures in the collection,
    	// returns false otherwise.
    	__checkReturn bool ParamsOK() throw()
    	{
    		return !m_bFailures;
    	}
     
    	// Returns the number of validation results in the collection.
    	__checkReturn int GetResultCount() throw()
    	{
    		return m_results.GetSize();
    	}
     
    	// Call this function to retrieve the name and type of a
    	// validation result based on its index in the collection.
    	// Returns true on success, false on failure.
    	//
    	// i        The index of a result managed by this collection.
    	//
    	// strName  On success, the name of the result with index i.
    	//
    	// type     On success, the type of the result with index i.
    	__checkReturn bool GetResultAt(__in int i, __out CStringA& strName, __out DWORD& type) throw()
    	{
    		if ( i >= 0 && i < m_results.GetSize())
    		{
    			_ATLTRY
    			{
    				strName = m_results.GetKeyAt(i);
    				type = m_results.GetValueAt(i);
    			}
    			_ATLCATCHALL()
    			{
    				return false;
    			}
    			return true;
    		}
    		return false;
    	}
     
    	DWORD m_dwFlags;
    protected:
    	CSimpleMap<CStringA, DWORD> m_results;
    	bool m_bFailures;
    }; // CAksValidateContext
     
     
    class CAksValidator
    {
    public:
    	template <class T, class TCompType>
    	static DWORD Validate(
    		__in T value,
    		__in TCompType nMinValue,
    		__in TCompType nMaxValue) throw()
    	{
    		DWORD dwRet = VALIDATION_S_OK;
    		if (value < static_cast<T>(nMinValue))
    			dwRet = VALIDATION_E_LENGTHMIN;
    		else if (value > static_cast<T>(nMaxValue))
    			dwRet = VALIDATION_E_LENGTHMAX;
    		return dwRet;
    	}
     
    	static DWORD Validate( __in LPCSTR pszValue, __in int nMinChars, __in int nMaxChars) throw()
    	{
    		DWORD dwRet = VALIDATION_S_OK;
    		if(!pszValue)
    		{
    			return VALIDATION_E_FAIL;
    		}
    		int nChars = (int) strlen(pszValue);
    		if (nChars < nMinChars)
    			dwRet = VALIDATION_E_LENGTHMIN;
    		else if (nChars > nMaxChars)
    			dwRet = VALIDATION_E_LENGTHMAX;
    		return dwRet;
    	}
    	static DWORD Validate( __in double dblValue, __in double dblMinValue, __in double dblMaxValue) throw()
    	{
    		DWORD dwRet = VALIDATION_S_OK;
    		if ( dblValue < (dblMinValue - ATL_EPSILON) )
    			dwRet = VALIDATION_E_LENGTHMIN;
    		else if ( dblValue > (dblMaxValue + ATL_EPSILON) )
    			dwRet = VALIDATION_E_LENGTHMAX;
    		return dwRet;
    	}
    }; // CAksValidator
     
    // This class provides functions for retrieving and validating named values.
    //
    // The named values are expected to be provided in string form by the class used as
    // the template parameter. CValidateObject provides the means of
    // retrieving these values converted to data types chosen by you. You can validate the values
    // by specifying a range for numeric values or by specifying a minimum and maximum length
    // for string values.
    //
    // Call one of the Exchange overloads to retrieve a named value converted to your chosen data type.
    // Call one of the Validate overloads to retrieve a named value converted to your chosen data type
    // and validated against a minimum and maximum value or length supplied by you.
    //
    // To add validation functionality to the class TLookupClass, derive that class from CValidateObject<TLookupClass>
    // and provide a Lookup function that takes a name as a string and returns the corresponding value
    // also as a string:
    //      LPCSTR Lookup(LPCSTR szName);
    template <class TLookupClass, class TValidator = CAksValidator>
    class CAksValidateObject
    {
    public:
    	// Exchange Routines
     
    	// Call this function to retrieve a named value converted to your chosen data type.
    	// Returns one of the following validation status codes:
    	//      VALIDATION_S_OK             The named value was found and could be converted successfully
    	//      VALIDATION_S_EMPTY          The name was present, but the value was empty
    	//      VALIDATION_E_PARAMNOTFOUND  The named value was not found
    	//      VALIDATION_E_INVALIDPARAM   The name was present, but the value could not be converted to the requested data type
    	//      VALIDATION_E_FAIL           An unspecified error occurred
    	// Pass a pointer to a validation context object if you want to add
    	// failures to the collection managed by that object.
    	template <class T>
    	ATL_NOINLINE __checkReturn DWORD Exchange(
    		__in LPCSTR szParam,
    		__out T* pValue,
    		__inout_opt CAksValidateContext *pContext = NULL) const throw()
    	{
    		DWORD dwRet = VALIDATION_E_PARAMNOTFOUND;
    		if (pValue)
    		{
    			_ATLTRY
    			{
    				const TLookupClass *pT = static_cast<const TLookupClass*>(this);
    				LPCSTR szValue = pT->Lookup(szParam);
    				if (szValue)
    				{
    					if (*szValue=='\0')
    						dwRet = VALIDATION_S_EMPTY; 
    					else
    					{
    						dwRet = ConvertNumber(szValue, pValue);
    					}
    				}
    			}
    			_ATLCATCHALL()
    			{
    				return VALIDATION_E_FAIL;
    			}
    		}
    		else
    			dwRet = VALIDATION_E_FAIL; // invalid input
     
    		if (pContext)
    			pContext->AddResult(szParam, dwRet);
    		return dwRet;
    	}
     
    	template<>
    	ATL_NOINLINE __checkReturn DWORD Exchange(
    		__in LPCSTR szParam,
    		__out_opt CStringA* pstrValue,
    		__in_opt CAksValidateContext *pContext) const throw()
    	{
    		_ATLTRY
    		{
    			LPCSTR pszValue = NULL;
    			DWORD dwRet = VALIDATION_E_PARAMNOTFOUND;
    			if (pstrValue)
    			{
    				dwRet = Exchange(szParam, &pszValue, pContext);
    				if (VALIDATION_SUCCEEDED(dwRet) && pstrValue != NULL)
    					*pstrValue = CA2T(pszValue);
    			}
    			else
    			{
    				dwRet = VALIDATION_E_FAIL; // invalid input
    				if (pContext)
    					pContext->AddResult(szParam, dwRet);
    			}
     
    			return dwRet;
    		}
    		_ATLCATCHALL()
    		{
    			return VALIDATION_E_FAIL;
    		}
    	}
     
    	template<>
    	ATL_NOINLINE __checkReturn DWORD Exchange(
    		__in LPCSTR szParam,
    		__deref_out_opt LPCSTR* ppszValue,
    		__inout_opt CAksValidateContext *pContext) const throw()
    	{
    		DWORD dwRet = VALIDATION_E_PARAMNOTFOUND;
    		if (ppszValue)
    		{
    			_ATLTRY
    			{
    				*ppszValue = NULL;
    				const TLookupClass *pT = static_cast<const TLookupClass*>(this);
    				LPCSTR szValue = pT->Lookup(szParam);
    				if (szValue)
    				{
    					if (*szValue=='\0')
    						dwRet = VALIDATION_S_EMPTY; 
    					else
    					{
    						*ppszValue = szValue;
    						dwRet = VALIDATION_S_OK;
    					}
    				}
    			}
    			_ATLCATCHALL()
    			{
    				return VALIDATION_E_FAIL;
    			}
    		}
    		else
    			dwRet = VALIDATION_E_FAIL; // invalid input
     
    		if (pContext)
    			pContext->AddResult(szParam, dwRet);
    		return dwRet;
    	}
     
    	template<>
    	ATL_NOINLINE __checkReturn DWORD Exchange(
    		__in LPCSTR szParam,
    		__out GUID* pValue,
    		__inout_opt CAksValidateContext *pContext) const throw()
    	{
    		DWORD dwRet = VALIDATION_E_PARAMNOTFOUND;
    		if (pValue)
    		{
    			_ATLTRY
    			{
    				const TLookupClass *pT = static_cast<const TLookupClass*>(this);
    				LPCSTR szValue = pT->Lookup(szParam);
    				if (szValue)
    				{
    					if (*szValue=='\0')
    						dwRet = VALIDATION_S_EMPTY; 
    					else
    					{						
    						if (S_OK != CLSIDFromString(CA2W(szValue), pValue))
    						{
    							dwRet = VALIDATION_E_INVALIDPARAM;
    						}
    						else
    							dwRet = VALIDATION_S_OK;
    					}
    				}
    			}
    			_ATLCATCHALL()
    			{
    				return VALIDATION_E_FAIL;
    			}
    		}
    		else
    			dwRet = VALIDATION_E_FAIL; // invalid input
     
    		if (pContext)
    			pContext->AddResult(szParam, dwRet);
    		return dwRet;
    	}
     
    	template<>
    	ATL_NOINLINE __checkReturn DWORD Exchange(
    		__in LPCSTR szParam,
    		__out bool* pbValue,
    		__inout_opt CAksValidateContext *pContext) const throw()
    	{
    		DWORD dwRet = VALIDATION_S_OK;
    		if (pbValue)
    		{
    			_ATLTRY
    			{
    				const TLookupClass *pT = static_cast<const TLookupClass*>(this);
    				LPCSTR szValue = pT->Lookup(szParam);
    				*pbValue = false;
    				if (szValue)
    				{
    					if (*szValue != '\0')
    						*pbValue = true;
    				}
    			}
    			_ATLCATCHALL()
    			{
    				return VALIDATION_E_FAIL;
    			}
    		}
    		else
    			dwRet = VALIDATION_E_FAIL; // invalid input
     
    		if (pContext)
    			pContext->AddResult(szParam, dwRet);
     
    		return dwRet;
    	}
     
    	__checkReturn DWORD ConvertNumber(__in LPCSTR szVal, __out ULONGLONG *pnVal) const throw()
    	{
    		if (!szVal)
    			return VALIDATION_E_FAIL;
     
    		ATLASSERT(pnVal);
    		if (!pnVal)
    			return VALIDATION_E_FAIL;
    		char *pEnd = NULL;
    		ULONGLONG n = 0;
    		errno_t errnoValue = AtlStrToNum(&n, szVal, &pEnd, 10);
    		if (pEnd == szVal || errnoValue == ERANGE)
    		{
    			return VALIDATION_E_INVALIDPARAM;
    		}
    		*pnVal = n;
    		return VALIDATION_S_OK;
    	}
     
    	__checkReturn DWORD ConvertNumber(__in LPCSTR szVal, __out LONGLONG *pnVal) const throw()
    	{
    		if (!szVal)
    			return VALIDATION_E_FAIL;
     
    		ATLASSERT(pnVal);
    		if (!pnVal)
    			return VALIDATION_E_FAIL;
    		char *pEnd = NULL;
    		LONGLONG n = 0;
    		errno_t errnoValue = AtlStrToNum(&n, szVal, &pEnd, 10);
    		if (pEnd == szVal || errnoValue == ERANGE)
    		{
    			return VALIDATION_E_INVALIDPARAM;
    		}
    		*pnVal = n;
    		return VALIDATION_S_OK;
    	}
     
    	__checkReturn DWORD ConvertNumber(__in LPCSTR szVal, __out double *pdblVal) const throw()
    	{
    		if (!szVal)
    			return VALIDATION_E_FAIL;
     
    		ATLASSERT(pdblVal);
    		if (!pdblVal)
    			return VALIDATION_E_FAIL;
    		char *pEnd = NULL;
    		double d = 0.0;
    		errno_t errnoValue = AtlStrToNum(&d, szVal, &pEnd);
    		if (pEnd == szVal || errnoValue == ERANGE)
    		{
    			return VALIDATION_E_INVALIDPARAM;
    		}
    		*pdblVal = d;
    		return VALIDATION_S_OK;
    	}
     
    	__checkReturn DWORD ConvertNumber(__in LPCSTR szVal, __out int *pnVal) const throw()
    	{
    		return ConvertNumber(szVal, (long*)pnVal);
    	}
     
    	__checkReturn DWORD ConvertNumber(__in LPCSTR szVal, __out unsigned int *pnVal) const throw()
    	{
    		return ConvertNumber(szVal, (unsigned long*)pnVal);
    	}
     
    	__checkReturn DWORD ConvertNumber(__in LPCSTR szVal, __out long *pnVal) const throw()
    	{
    		if (!szVal)
    			return VALIDATION_E_FAIL;
     
    		ATLASSERT(pnVal);
    		if (!pnVal)
    			return VALIDATION_E_FAIL;
    		char *pEnd = NULL;
    		long n = 0;
    		errno_t errnoValue = AtlStrToNum(&n, szVal, &pEnd, 10);
    		if (pEnd == szVal || errnoValue == ERANGE)
    		{
    			return VALIDATION_E_INVALIDPARAM;
    		}
    		*pnVal = n;
    		return VALIDATION_S_OK;
    	}
     
    	__checkReturn DWORD ConvertNumber(__in LPCSTR szVal, __out unsigned long *pnVal) const throw()
    	{
    		if (!szVal)
    			return VALIDATION_E_FAIL;
     
    		ATLASSERT(pnVal);
    		if (!pnVal)
    			return VALIDATION_E_FAIL;
    		char *pEnd = NULL;
    		unsigned long n = 0;
    		errno_t errnoValue = AtlStrToNum(&n, szVal, &pEnd, 10);
    		if (pEnd == szVal || errnoValue == ERANGE)
    		{
    			return VALIDATION_E_INVALIDPARAM;
    		}
    		*pnVal = n;
    		return VALIDATION_S_OK;
    	}
     
    	__checkReturn DWORD ConvertNumber(__in LPCSTR szVal, __out short *pnVal) const throw()
    	{
    		if (!szVal)
    			return VALIDATION_E_FAIL;
     
    		ATLASSERT(pnVal);
    		if (!pnVal)
    			return VALIDATION_E_FAIL;
    		long nVal = 0;
    		DWORD dwRet = ConvertNumber(szVal, &nVal);
    		if (dwRet == VALIDATION_S_OK)
    		{
    			// clamp to the size of a short
    			if(nVal <= SHRT_MAX &&
    				nVal >= SHRT_MIN)
    			{
    				*pnVal = (short)nVal;
    			}
    			else
    			{
    				dwRet = VALIDATION_E_INVALIDPARAM;
    			}
    		}
    		return dwRet;
    	};
     
    	__checkReturn DWORD ConvertNumber(__in LPCSTR szVal, __out unsigned short *pnVal) const throw()
    	{
    		if (!szVal)
    			return VALIDATION_E_FAIL;
     
    		ATLASSERT(pnVal);
    		if (!pnVal)
    			return VALIDATION_E_FAIL;
    		unsigned long nVal = 0;
    		DWORD dwRet = ConvertNumber(szVal, &nVal);
    		if (dwRet == VALIDATION_S_OK)
    		{
    			// clamp to the size of a short
    			if(nVal <= USHRT_MAX &&
    			   nVal >= 0)
    			{
    				*pnVal = (unsigned short)nVal;
    			}
    			else
    			{
    				dwRet = VALIDATION_E_INVALIDPARAM;
    			}
    		}
    		return dwRet;
    	};
     
    	// Call this function to retrieve a named value converted to your chosen data type
    	// and validated against a minimum and maximum value or length supplied by you.
    	//
    	// Returns one of the following validation status codes:
    	//      VALIDATION_S_OK             The named value was found and could be converted successfully
    	//      VALIDATION_S_EMPTY          The name was present, but the value was empty
    	//      VALIDATION_E_PARAMNOTFOUND  The named value was not found
    	//      VALIDATION_E_INVALIDPARAM   The name was present, but the value could not be converted to the requested data type
    	//      VALIDATION_E_LENGTHMIN      The name was present and could be converted to the requested data type, but the value was too small
    	//      VALIDATION_E_LENGTHMAX      The name was present and could be converted to the requested data type, but the value was too large
    	//      VALIDATION_E_FAIL           An unspecified error occurred
    	//
    	// Validate can be used to convert and validate name-value pairs
    	// such as those associated with HTTP requests (query string, form fields, or cookie values).  
    	// The numeric specializations validate the minimum and maximum value.
    	// The string specializations validate the minimum and maximum length.
    	//
    	// Pass a pointer to a validation context object if you want to add
    	// failures to the collection managed by that object.
    	//
    	// Note that you can validate the value of a parameter without
    	// storing its value by passing NULL for the second parameter. However
    	// if you pass NULL for the second parameter, make sure you cast the NULL to a 
    	// type so that the compiler will call the correct specialization of Validate.
    	template <class T, class TCompType>
    	ATL_NOINLINE __checkReturn DWORD Validate(
    		__in LPCSTR Param,
    		__out_opt T *pValue,
    		__in TCompType nMinValue,
    		__in TCompType nMaxValue,
    		__inout_opt CAksValidateContext *pContext = NULL) const throw()
    	{
    		T value;
    		DWORD dwRet = Exchange(Param, &value, pContext);
    		if ( dwRet == VALIDATION_S_OK )
    		{
    			if (pValue)
    				*pValue = value;
    			dwRet = TValidator::Validate(value, nMinValue, nMaxValue);
    			if (pContext && dwRet != VALIDATION_S_OK)
    				pContext->AddResult(Param, dwRet);
    		}
    		else if (dwRet == VALIDATION_S_EMPTY &&
    				 !IsNullByType(nMinValue))
    		{
    				 dwRet = VALIDATION_E_LENGTHMIN;
    				 if (pContext)
    				 {
    					pContext->SetResultAt(Param, VALIDATION_E_LENGTHMIN);
    				 }
    		}
     
    		return dwRet;
    	}
     
    	// Specialization for strings. Comparison is for number of characters.
    	template<>
    	ATL_NOINLINE __checkReturn DWORD Validate(
    		__in LPCSTR Param,
    		__deref_opt_out LPCSTR* ppszValue,
    		__in int nMinChars,
    		__in int nMaxChars,
    		__inout_opt CAksValidateContext *pContext) const throw()
    	{
    		LPCSTR pszValue = NULL;
    		DWORD dwRet = Exchange(Param, &pszValue, pContext);
    		if (dwRet == VALIDATION_S_OK )
    		{
    			if (ppszValue)
    				*ppszValue = pszValue;
    			dwRet = TValidator::Validate(pszValue, nMinChars, nMaxChars);
    			if (pContext && dwRet != VALIDATION_S_OK)
    				pContext->AddResult(Param, dwRet);
    		}
    		else if (dwRet == VALIDATION_S_EMPTY &&
    				 nMinChars > 0)
    		{
    				 dwRet = VALIDATION_E_LENGTHMIN;
    				 if (pContext)
    				 {
    					pContext->SetResultAt(Param, VALIDATION_E_LENGTHMIN);
    				 }
    		}
     
     
    		return dwRet;
    	}
     
    	// Specialization for CStringA so caller doesn't have to cast CStringA
    	template<>
    	ATL_NOINLINE __checkReturn DWORD Validate(
    		__in LPCSTR Param,
    		__out_opt CStringA* pstrValue,
    		__in int nMinChars,
    		__in int nMaxChars,
    		__inout_opt CAksValidateContext *pContext) const throw()
    	{
    		_ATLTRY
    		{
    			LPCSTR szValue;
    			DWORD dwRet = Validate(Param, &szValue, nMinChars, nMaxChars, pContext);
    			if (pstrValue && dwRet == VALIDATION_S_OK )
    				*pstrValue = szValue;
    			return dwRet;
    		}
    		_ATLCATCHALL()
    		{
    			return VALIDATION_E_FAIL;
    		}
    	}
     
    	// Specialization for doubles, uses a different comparison.
    	template<>
    	ATL_NOINLINE __checkReturn DWORD Validate(
    		__in LPCSTR Param,
    		__out_opt double* pdblValue,
    		__in double dblMinValue,
    		__in double dblMaxValue,
    		__inout_opt CAksValidateContext *pContext) const throw()
    	{
    		double dblValue;
    		DWORD dwRet = Exchange(Param, &dblValue, pContext);
    		if (dwRet == VALIDATION_S_OK)
    		{
    			if (pdblValue)
    				*pdblValue = dblValue;
    			dwRet = TValidator::Validate(dblValue, dblMinValue, dblMaxValue);
    			if (pContext && dwRet != VALIDATION_S_OK)
    				pContext->AddResult(Param, dwRet);
    		}
    		else if (dwRet == VALIDATION_S_EMPTY &&
    				 (dblMinValue < -ATL_EPSILON ||
    				 dblMinValue > ATL_EPSILON))
    		{
    			dwRet = VALIDATION_E_LENGTHMIN;
    			if (pContext)
    			{
    				pContext->SetResultAt(Param, VALIDATION_E_LENGTHMIN);
    			}
    		}
    		return dwRet;
    	}
    };  // CAksValidateObject
     
    class CAksDataSet : public CAksValidateObject<CAksDataSet>
    {
    	typedef CAksValidateObject<CAksDataSet> baseType;
    	typedef CAtlMap<CStringA, CStringA, CStringElementTraits<CStringA>, CStringElementTraits<CStringA> > mapType;
     
    	// cette classe permet de considérer ou d'ignorer 
    	// si ses valeurs chaînes sont sensibles à la case
    	// la clé entière commence à 1
    	class CAksSimpleMap : public CSimpleMap<ULONG, CStringA>
    	{
    	public:
    		CAksSimpleMap()
    		{
    			m_bMatchCase = false;  // no case sensitive by default
    		}
     
    		CStringA Lookup(const ULONG& key) const		// cette méthode surcharge celle de la classe de base
    		{
    			int nIndex = FindKey(key);
    			if(nIndex == -1)
    				return CStringA();			// à cause de la conversion qui doit être fournit ici
    			return GetValueAt(nIndex);
    		}
     
    		ULONG ReverseLookup(const CStringA& val) const
    		{
    			if(val.IsEmpty())
    				return 0;  // bad key
     
    			if(m_bMatchCase)
    				return CSimpleMap<ULONG, CStringA>::ReverseLookup(val);
     
    			// ignoring case sentive of val and lookup its key
    			CStringA strNewValue(val);
    			int nCount = GetSize();
    			for(int nIndex = 0; nIndex < nCount; nIndex++)
    			{
    				CStringA strOldValue(GetValueAt(nIndex));
    				if(strOldValue.CompareNoCase(strNewValue) == 0)
    					return GetKeyAt(nIndex); // or return nIndex + 1
    			}
    			return 0;  // bad key
    		}
     
    	public:
    		bool m_bMatchCase;
    	};
     
    	typedef CAksSimpleMap simpleMapType;
     
    public:
    	CAksDataSet()
    	{
    		MatchCase(false);
    	}
     
    	CAksDataSet(const CAksDataSet& aDataSet)
    	{
    		*this = aDataSet;
    	}
     
    	~CAksDataSet()
    	{
     
    	}
     
    	bool MatchCase(bool bMatchCase = false)
    	{
    		bool bValue = m_Indexes.m_bMatchCase;
    		m_Indexes.m_bMatchCase = bMatchCase;
    		return bValue;
    	}
     
    	ATL_NOINLINE bool AddValue(CStringA strName, CStringA strValue)
    	{
    		if(strName.IsEmpty())
    			return false;
     
    		CStringA strOriginalName(strName);
    		if( !m_Indexes.m_bMatchCase )
    			strName.MakeUpper();
     
    		const mapType::CPair* pPair = m_Values.Lookup(strName);
    		if( !pPair )
    		{	// this is the first time !!!
    			if(m_Values.SetAt(strName, strValue))
    			{
    				ULONG newKey = (ULONG) m_Values.GetCount();
    				ATLASSERT(newKey > 0);
    				if(m_Indexes.Add(newKey, CStringA(strOriginalName))) // newKey begin by 1
    					return true;
    			}
    		}
    		else if(m_Values.SetAt(strName, strValue))  // we replace the existing value
    		{	// ReverseLookup() hold case sensitive value 
    			ULONG Key = m_Indexes.ReverseLookup(CStringA(strOriginalName));
    			ATLASSERT(Key > 0);
    			if(m_Indexes.SetAt(Key, CStringA(strOriginalName))) // we replace the existing key
    				return true;
    		}		
    		return false;
    	}
     
    	bool AddValue(CStringA strName, LPCSTR szValue)
    	{
    		if(szValue == NULL)		// test l'existence mais pas le contenu du buffer szValue
    			return false;
    		return AddValue(strName, CStringA(szValue));
    	}
     
    	bool AddValue(CStringA strName, LPCWSTR szValue)
    	{
    		if(szValue == NULL)		// test l'existence mais pas le contenu du buffer szValue
    			return false;
    		return AddValue(strName, CStringA(szValue));
    	}
     
    	bool AddValue(CStringA strName, BYTE* szValue)
    	{
    		if(szValue == NULL)		// test l'existence mais pas le contenu du buffer szValue
    			return false;
    		return AddValue(strName, CStringA(szValue));
    	}
     
    	bool AddValue(CStringA strName, BSTR szValue)
    	{
    		if(szValue == NULL)		// test l'existence mais pas le contenu du buffer szValue
    			return false;
    		return AddValue(strName, CStringA(szValue));
    	}
     
    	bool AddValue(CStringA strName, double dValue)
    	{
    		CStringA strValue;
    		strValue.Format("%lf", dValue);
    		return AddValue(strName, strValue);
    	}
     
    	bool AddValue(CStringA strName, float fValue)
    	{
    		CStringA strValue;
    		strValue.Format("%f", fValue);
    		return AddValue(strName, strValue);
    	}
     
    	bool ATL_NOINLINE AddValue(CStringA strName, ULONGLONG ui64Value)
    	{
    		CStringA strValue;
    		strValue.Format("%I64u", ui64Value);
    		return AddValue(strName, strValue);
    	}
     
    	bool ATL_NOINLINE AddValue(CStringA strName, LONGLONG i64Value)
    	{
    		CStringA strValue;
    		strValue.Format("%I64d", i64Value);
    		return AddValue(strName, strValue);
    	}
     
    	bool AddValue(CStringA strName, long unsigned int luiValue)
    	{
    		CStringA strValue;
    		strValue.Format("%lu", luiValue);
    		return AddValue(strName, strValue);
    	}
     
    	bool ATL_NOINLINE AddValue(CStringA strName, long lValue)
    	{
    		CStringA strValue;
    		strValue.Format("%ld", lValue);
    		return AddValue(strName, strValue);
    	}
     
    	bool AddValue(CStringA strName, unsigned int uiValue)
    	{
    		CStringA strValue;
    		strValue.Format("%u", uiValue);
    		return AddValue(strName, strValue);
    	}
     
    	bool AddValue(CStringA strName, int iValue)
    	{
    		CStringA strValue;
    		strValue.Format("%d", iValue);
    		return AddValue(strName, strValue);
    	}
     
    	bool AddValue(CStringA strName, short unsigned int suiValue)
    	{
    		CStringA strValue;
    		strValue.Format("%hu", suiValue);
    		return AddValue(strName, strValue);
    	}
     
    	bool AddValue(CStringA strName, short sValue)
    	{
    		CStringA strValue;
    		strValue.Format("%hd", sValue);
    		return AddValue(strName, strValue);
    	}
     
    	bool ATL_NOINLINE AddValue(CStringA strName, bool bValue)
    	{
    		CHAR szValue[2];
    		szValue[0] = (bValue? '1' : '\0');
    		szValue[1] = '\0';
    		return AddValue(strName, szValue);
    	}
     
    	bool AddValue(CStringA strName, GUID guid)
    	{
    		CComBSTR bstr(guid);
    		CStringA strGuid(bstr);
    		return AddValue(strName, strGuid);
    	}
     
    	bool AddValue(CStringA strName, COleDateTime oleDate)
    	{
    		DATE date = oleDate.m_dt;
    		return AddValue(strName, date);
    	}
     
    	bool AddValue(CStringA strName, char ch)
    	{
    		return AddValue(strName, CStringA(ch));
    	}
     
    	bool AddValue(long nName, CStringA strValue)
    	{
    		CStringA strName;
    		strName.Format("%ld", nName);
    		return AddValue(strName, strValue);
    	}
     
    	bool AddValue(long nName, long lValue)
    	{
    		CStringA strValue;
    		strValue.Format("%ld", lValue);
    		return AddValue(nName, strValue);
    	}
     
    	bool AddValue(long nName, double dValue)
    	{
    		CStringA strValue;
    		strValue.Format("%lf", dValue);
    		return AddValue(nName, strValue);
    	}
     
    	bool AddValue(long nName, GUID guidValue)
    	{
    		CComBSTR bstr(guidValue);
    		CStringA strValue(bstr);
    		return AddValue(nName, strValue);
    	}
     
    	bool AddValue(double dName, CStringA strValue)
    	{
    		CStringA strName;
    		strName.Format("%lf", dName);
    		return AddValue(strName, strValue);
    	}
     
    	bool AddValue(double dName, long lValue)
    	{
    		CStringA strValue;
    		strValue.Format("%ld", lValue);
    		return AddValue(dName, strValue);
    	}
     
    	bool AddValue(double dName, double dValue)
    	{
    		CStringA strValue;
    		strValue.Format("%lf", dValue);
    		return AddValue(dName, strValue);
    	}
     
    	bool AddValue(double dName, GUID guidValue)
    	{
    		CComBSTR bstr(guidValue);
    		CStringA strValue(bstr);
    		return AddValue(dName, strValue);
    	}
     
    	bool AddValue(GUID guidName, CStringA strValue)
    	{
    		CComBSTR bstr(guidName);
    		CStringA strName(bstr);
    		return AddValue(strName, strValue);
    	}
     
    	bool AddValue(GUID guidName, long lValue)
    	{
    		CStringA strValue;
    		strValue.Format("%ld", lValue);
    		return AddValue(guidName, strValue);
    	}
     
    	bool AddValue(GUID guidName, double dValue)
    	{
    		CStringA strValue;
    		strValue.Format("%lf", dValue);
    		return AddValue(guidName, strValue);
    	}
     
    	bool AddValue(GUID guidName, GUID guidValue)
    	{
    		CComBSTR bstr(guidValue);
    		CStringA strValue(bstr);
    		return AddValue(guidName, strValue);
    	}
     
    	bool ATL_NOINLINE AddVariant(CStringA strName, CAksVariant varValue)
    	{
    		switch(varValue.m_vtOperation)
    		{
    		case VT_I1:			return AddValue(strName, CStringA((char)varValue));
    		case VT_I2:			return AddValue(strName, (short)varValue);
    		case VT_I4:			return AddValue(strName, (long)varValue);
     
    		case VT_CY:			return AddValue(strName, ((CY)varValue).int64);
    		case VT_DECIMAL:	return AddValue(strName, (LONGLONG)((DECIMAL)varValue).Lo64);
     
    		case VT_UI1:		return AddValue(strName, (long)(BYTE)varValue);
    		case VT_UI2:		return AddValue(strName, (unsigned short)varValue);
    		case VT_UI4:		return AddValue(strName, (unsigned long)varValue);
     
    		case VT_INT:		return AddValue(strName, (int)varValue);
    		case VT_UINT:		return AddValue(strName, (unsigned int)varValue);
     
    #if (_WIN32_WINNT >= 0x0501)
    		case VT_I8:			return AddValue(strName, (__int64)varValue);
    		case VT_UI8:		return AddValue(strName, (unsigned __int64)varValue);
    #endif
     
    		case VT_R4:			return AddValue(strName, (float)varValue);
    		case VT_R8:			return AddValue(strName, (double)varValue);
    		case VT_DATE:		return AddValue(strName, COleDateTime((DATE)varValue));
     
    		case VT_BSTR:		return AddValue(strName, CStringA(((_bstr_t)varValue).GetBSTR()));
     
    		default:
    			return false;
    		}
    	}
     
    	bool AddVariant(long nName, CAksVariant varValue)
    	{
    		CStringA strName;
    		strName.Format("%ld", nName);
    		return AddVariant(strName, varValue);
    	}
     
    	bool AddVariant(double dName, CAksVariant varValue)
    	{
    		CStringA strName;
    		strName.Format("%lf", dName);
    		return AddVariant(strName, varValue);
    	}
     
    	bool AddVariant(GUID guidName, CAksVariant varValue)
    	{
    		CComBSTR bstr(guidName);
    		CStringA strName(bstr);
    		return AddVariant(strName, varValue);
    	}
     
    	ULONG ATL_NOINLINE GetCount() const throw()
    	{	
    		size_t nValuesSize = m_Values.GetCount();
    		size_t nIndexSize = m_Indexes.GetSize();
    		ATLASSERT(nValuesSize == nIndexSize);
    		return (nValuesSize == nIndexSize)? (ULONG)nValuesSize : 0;
    	}
     
    	bool ATL_NOINLINE IsDataPresent(CStringA strName) const
    	{
    		if ( !GetCount() )
    			return false;
     
    		CStringA strOriginalName = strName;
    		if( !m_Indexes.m_bMatchCase )
    			strName.MakeUpper();
     
    		const mapType::CPair* pPair = m_Values.Lookup(strName);
    		if( !pPair )
    			return false;
     
    		// here data is present
    		ULONG iItem = m_Indexes.ReverseLookup(strOriginalName);
    		ATLASSERT(iItem != 0); // ensure that it is present
    		return (iItem == 0)? false: true;
    	}
     
    	bool IsEmpty() const
    	{
    		return (m_Values.IsEmpty() && !m_Indexes.GetSize())? true: false;
    	}
     
    	// toute classe dérivée de CValidateObject doit fournir ce prototype de fonction membre
    	LPCSTR ATL_NOINLINE Lookup(LPCSTR szName) const throw() 
    	{
    		_ATLTRY
    		{
    			if (!szName)
    				return NULL;
     
    			if ( !m_Values.GetCount() )
    				return NULL;
     
    			CStringA strName = szName;
    			if( !m_Indexes.m_bMatchCase )
    				strName.MakeUpper();
     
    			const mapType::CPair* pPair = m_Values.Lookup(strName);
    			if (pPair)
    				return (LPCSTR) pPair->m_value;
    		}
    		_ATLCATCHALL()
    		{
    		}
    		return NULL;
    	}
     
    	LPCSTR Lookup(CStringA strName) const throw()
    	{
    		return Lookup(strName.GetString());
    	}
     
    	bool ATL_NOINLINE LookupAt(ULONG iBasedZeroIndex, CStringA& strName, CStringA& strValue) const throw()
    	{
    		_ATLTRY
    		{
    			ULONG nCount = (ULONG) m_Indexes.GetSize();
    			if(iBasedZeroIndex >= nCount)
    				return false;
     
    			strName = m_Indexes.GetValueAt(iBasedZeroIndex); // return the orignal name
    			if(strName.IsEmpty())
    				return false;
     
    			LPCSTR szValue = Lookup(strName);
    			if( !szValue )
    				return false;
     
    			strValue = szValue;
    			return true;
    		}
    		_ATLCATCHALL()
    		{
    			return false;
    		}
    	}
     
    	ATL_NOINLINE POSITION GetFirstPosition()
    	{
    		if(!IsEmpty())
    		{
    			m_Pos = 0;
    			return (POSITION) &m_Pos;
    		}
    		return NULL;	
    	}
     
    	ATL_NOINLINE bool GetNext(POSITION& pos, CStringA& strName, CStringA& strValue) const
    	{
    		strName.Empty();
    		strValue.Empty();
    		if( !pos )
    			return false;
    		ULONG* piItem = (ULONG*) pos;
    		ATLASSERT(piItem);
    		if( !piItem )
    			return false;
    		ULONG nCount = GetCount();
    		if( *piItem < nCount )
    		{
    			bool bRet = LookupAt(*piItem, strName, strValue);
    			ATLASSERT(bRet);
    			if(bRet)
    			{
    				(*piItem)++;
    			}
    		}
    		if(*piItem >= nCount)
    			pos = NULL;
    		return true;
    	}
     
    	bool ATL_NOINLINE RemoveData(CStringA strName)
    	{
    		if(strName.IsEmpty())
    			return false;
     
    		CStringA strOriginalName = strName;
    		if( !m_Indexes.m_bMatchCase )
    			strName.MakeUpper();
     
    		ULONG Key = m_Indexes.ReverseLookup(strOriginalName);
    		if(Key == 0)
    			return false;
     
    		// On rédéfinit les valeurs associées aux indexes en mappant les valeurs
    		// vers leurs indexes respectifs diminués d'une unité à partir de l'élément à supprimer.
    		if(m_Values.RemoveKey(strName)) // on suprime l'élément de l'ensemble des valeurs
    		{
    			ULONG nCount = (ULONG) m_Indexes.GetSize();
    			if(nCount == 1)  // s'il n'y avait qu'un seul élément
    				return (m_Indexes.Remove(nCount)? true: false);	// on retourne en le supprimant de la table des indexes
     
    			ULONG i = Key+1;		// on définit l'indexe supérieur juste après l'élément supprimé.
    			while(i <= nCount)
    			{
    				strName = m_Indexes.Lookup(i);	// on récupère le nom d'indexe supérieur
    				if(strName.IsEmpty())
    					return false;
    				if( !m_Indexes.SetAt(i-1, strName) ) // qu'on place à l'indexe inférieur
    					return false;
    				i++;
    			}
    			// En fin de compte c'est le dernier élément qui est effectivement supprimé!!!
    			return (m_Indexes.Remove(nCount)? true: false);	// on supprime le dernier élément qui cause un doublon.
    		}
    		return false;
    	}
     
    	void Clear()
    	{
    		CStringA strEmpty;
    		strEmpty.Empty();
    		Fill(strEmpty);
    	}
     
    	void RemoveAll()
    	{
    		m_Values.RemoveAll();
    		m_Indexes.RemoveAll();
    	}
     
    	void Reset()
    	{
    		RemoveAll();
    		MatchCase(false);
    	}
     
    	void ATL_NOINLINE Fill(CStringA strSameValue)
    	{
    		ULONG nItem = GetCount();
     
    		for(ULONG iItem = 0; iItem < nItem; iItem++)
    		{
    			CStringA strName;
    			CStringA strValue;
    			bool bRet = LookupAt(iItem, strName, strValue);
    			if(bRet)
    				AddValue(strName, strSameValue);
    		}
    	}
     
    	void Fill(double dValue)
    	{
    		CStringA strValue;
    		strValue.Format("%lf", dValue);
    		Fill(strValue);
    	}
     
    	void Fill(float fValue)
    	{
    		Fill((double) fValue);
    	}
     
    	void Fill(long nValue)
    	{
    		CStringA strValue;
    		strValue.Format("%ld", nValue);
    		Fill(strValue);
    	}
     
    	void Fill(int nValue)
    	{
    		Fill((long) nValue);
    	}
     
    	void ATL_NOINLINE Fill(bool bValue)
    	{
    		CHAR szValue[2];
    		szValue[0] = (bValue? '1' : '\0');
    		szValue[1] = '\0';
    		return Fill(CStringA(szValue));
    	}
     
    	bool ATL_NOINLINE Fill(GUID guid)
    	{
    		CComBSTR bstrGuid(guid);
    		CStringA strGuid(bstrGuid);
    		Fill(strGuid);
    		return true;
    	}
     
    	void Fill(COleDateTime oleDate)
    	{
    		DATE date = oleDate;
    		Fill(date);
    	}
     
    	bool ReverseKeyValue()
    	{
    		AKS::CAksDataSet aDataSet;
    		aDataSet.m_Indexes.m_bMatchCase = this->m_Indexes.m_bMatchCase;
    		ULONG nItem = GetCount();
    		for(ULONG iItem = 0; iItem < nItem; iItem++)
    		{
    			CStringA strName;
    			CStringA strValue;
    			bool bRet = LookupAt(iItem, strName, strValue);
    			ATLASSERT(bRet);
    			if(bRet)
    				aDataSet.AddValue(strValue, strName);
    		}
    		if(nItem)
    			*this = aDataSet;
    		return nItem? true: false;
    	}
     
    	// Exchange methods
    public:
    	template <class T>
    	DWORD Exchange(LPCSTR szParam, T* pValue, CAksValidateContext *pContext = NULL) const throw()
    	{
    		CStringA strName = szParam;
    		if( !m_Indexes.m_bMatchCase )
    			strName.MakeUpper();
     
    		return baseType::Exchange<T>(strName.GetString(), pValue, pContext);
    	}
     
    	template <>
    	DWORD Exchange(LPCSTR szParam, CStringA* pstrValue, CAksValidateContext *pContext) const throw()
    	{
    		CStringA strName = szParam;
    		if( !m_Indexes.m_bMatchCase )
    			strName.MakeUpper();
     
    		return baseType::Exchange<CStringA>(strName.GetString(), pstrValue, pContext);
    	}
     
    	template<>
    	DWORD Exchange(LPCSTR szParam, LPCSTR* ppszValue, CAksValidateContext *pContext) const throw()
    	{
    		CStringA strName = szParam;
    		if( !m_Indexes.m_bMatchCase )
    			strName.MakeUpper();
     
    		return baseType::Exchange<LPCSTR>(strName.GetString(), ppszValue, pContext);
    	}
     
    	template<>
    	DWORD Exchange(LPCSTR szParam, GUID* pguidValue, CAksValidateContext *pContext) const throw()
    	{
    		CStringA strName = szParam;
    		if( !m_Indexes.m_bMatchCase )
    			strName.MakeUpper();
     
    		return baseType::Exchange<GUID>(strName.GetString(), pguidValue, pContext);
    	}
     
    	template<>
    	DWORD Exchange(LPCSTR szParam, bool* pbValue, CAksValidateContext *pContext) const throw()
    	{
    		CStringA strName = szParam;
    		if( !m_Indexes.m_bMatchCase )
    			strName.MakeUpper();
     
    		if(IsDataPresent(strName))
    			return baseType::Exchange<bool>(strName.GetString(), pbValue, pContext);
    		else
    			return VALIDATION_E_INVALIDPARAM;
    	}
     
    	template <>
    	DWORD ATL_NOINLINE Exchange(LPCSTR szParam, float* pValue, CAksValidateContext *pContext) const throw()
    	{
    		_ATLTRY
    		{
    			if( !pValue )
    				return VALIDATION_E_FAIL;
    			double dValue;
    			DWORD dwRet = Exchange(szParam, &dValue, pContext);
    			if (dwRet == VALIDATION_S_OK)
    				*pValue = (float)dValue;
    			return dwRet;
    		}
    		_ATLCATCHALL()
    		{
    			return VALIDATION_E_FAIL;
    		}
    	}
     
    	template <>
    	DWORD Exchange(LPCSTR szParam, CComBSTR* pbstrValue, CAksValidateContext *pContext) const throw()
    	{
    		_ATLTRY
    		{
    			if( !pbstrValue )
    				return VALIDATION_E_FAIL;
    			CStringA strValue;
    			DWORD dwRet = Exchange(szParam, &strValue, pContext);
    			if(dwRet == VALIDATION_S_OK)
    				*pbstrValue = strValue;
    			return dwRet;
    		}
    		_ATLCATCHALL()
    		{
    			return VALIDATION_E_FAIL;
    		}
    	}
     
    	template<>
    	DWORD Exchange(LPCSTR szParam, BSTR* pbstrValue, CAksValidateContext *pContext) const throw()
    	{
    		_ATLTRY
    		{
    			if( !pbstrValue )
    				return VALIDATION_E_FAIL;
    			CStringA strValue;
    			DWORD dwRet = Exchange(szParam, &strValue, pContext);
    			if(dwRet == VALIDATION_S_OK)
    			{
    				CComBSTR bstrValue(strValue);
    				HRESULT hr = bstrValue.CopyTo(pbstrValue);
    				ATLASSERT(hr == S_OK);
    			}
    			return dwRet;
    		}
    		_ATLCATCHALL()
    		{
    			return VALIDATION_E_FAIL;
    		}
    	}
     
    	template<>
    	DWORD Exchange(LPCSTR szParam, char* pchValue, CAksValidateContext *pContext) const throw()
    	{
    		_ATLTRY
    		{
    			if( !pchValue )
    				return VALIDATION_E_FAIL;
    			CStringA strValue;
    			DWORD dwRet = Exchange(szParam, &strValue, pContext);
    			if(dwRet == VALIDATION_S_OK)
    			{
    				*pchValue =  strValue.GetAt(0);
    			}
    			return dwRet;
    		}
    		_ATLCATCHALL()
    		{
    			return VALIDATION_E_FAIL;
    		}
    	}
     
    	ATL_NOINLINE DWORD ExchangeStringT(
    		LPCSTR szParam, 
    		LPSTR pszValue, 
    		const ULONG nSize,
    		bool bTrunc = false,
    		CAksValidateContext *pContext = NULL) const throw()
    	{
    		if( pszValue == NULL || nSize == 0)
    			return VALIDATION_E_FAIL;
     
    		_ATLTRY
    		{
    			pszValue[0] = '\0';
    			CStringA strValue;
    			DWORD dwRet = Exchange(szParam, &strValue, pContext);
    			if(dwRet == VALIDATION_S_OK)
    			{
    				if(AssignString(pszValue, nSize, strValue, bTrunc) != S_OK)
    					dwRet = VALIDATION_E_FAIL;
    			}
    			return dwRet;
    		}
     
    		_ATLCATCHALL()
    		{
    			return VALIDATION_E_FAIL;
    		}
    	}
     
    	DWORD ExchangeStringT(
    		LPCSTR szParam,
    		BYTE* pbyteValue,
    		const ULONG nSize,
    		bool bTrunc = false,
    		CAksValidateContext *pContext = NULL) const throw()
    	{
    		return ExchangeStringT(szParam, (LPSTR) pbyteValue, nSize, bTrunc, pContext);
    	}
     
    	DWORD ExchangeStringT(
    		LPCSTR szParam,
    		LPWSTR pszValue,
    		const ULONG nSize,
    		bool bTrunc = false,
    		CAksValidateContext *pContext = NULL) const throw()
    	{
    		CStringA strValue(pszValue);
    		return ExchangeStringT(szParam, (LPSTR)(LPCSTR) strValue, nSize, bTrunc, pContext);
    	}
     
    	ATL_NOINLINE DWORD Exchange(
    		LPCSTR szParam,
    		COleDateTime* pValue,
    		CAksValidateContext *pContext = NULL) const throw()
    	{
    		_ATLTRY
    		{
    			if( !pValue )
    				return VALIDATION_E_FAIL;
    			DATE dt;
    			DWORD dwRet = Exchange(szParam, &dt, pContext);
    			if (dwRet == VALIDATION_S_OK)
    				*pValue = dt;
    			return dwRet;
    		}
    		_ATLCATCHALL()
    		{
    			return VALIDATION_E_FAIL;
    		}
    	}
     
    	ATL_NOINLINE DWORD ExchangeVariant(LPCSTR szParam, CAksVariant* pvarValue) const throw()
    	{
    		if( !pvarValue )
    			return VALIDATION_E_FAIL;
     
    		_ATLTRY
    		{
    			CStringA strValue;
    			DWORD dwRet = Exchange(szParam, &strValue, NULL);
    			if(dwRet == VALIDATION_S_OK)
    				*pvarValue = strValue;
    			return dwRet;
    		}
     
    		_ATLCATCHALL()
    		{
    			return VALIDATION_E_FAIL;
    		}
    	}
     
    	// Validate methods
    public:
    	template <class T, class TCompType>
    	DWORD Validate(
    		LPCSTR szParam, 
    		T *pValue, 
    		TCompType nMinValue, 
    		TCompType nMaxValue, 
    		CAksValidateContext *pContext = NULL) const throw()
    	{
    		CStringA strName = szParam;
    		if( !m_Indexes.m_bMatchCase )
    			strName.MakeUpper();
     
    		return baseType::Validate<T, TCompType>(strName.GetString(), pValue, nMinValue, nMaxValue, pContext);
    	}
     
    	template<>
    	DWORD Validate(
    		LPCSTR szParam, 
    		LPCSTR* ppszValue, 
    		int nMinChars, 
    		int nMaxChars, 
    		CAksValidateContext *pContext) const throw()
    	{
    		CStringA strName = szParam;
    		if( !m_Indexes.m_bMatchCase )
    			strName.MakeUpper();
     
    		return baseType::Validate<LPCSTR, int>(strName.GetString(), ppszValue, nMinChars, nMaxChars, pContext);
    	}
     
    	template<>
    	DWORD Validate(
    		LPCSTR szParam, 
    		CStringA* pstrValue, 
    		int nMinChars, 
    		int nMaxChars, 
    		CAksValidateContext *pContext) const throw()
    	{
    		CStringA strName = szParam;
    		if( !m_Indexes.m_bMatchCase )
    			strName.MakeUpper();
     
    		return baseType::Validate<CStringA, int>(strName.GetString(), pstrValue, nMinChars, nMaxChars, pContext);
    	}
     
    	template<>
    	DWORD Validate(
    		LPCSTR szParam,
    		double* pdblValue,
    		double dblMinValue,
    		double dblMaxValue,
    		CAksValidateContext *pContext) const throw()
    	{
    		CStringA strName = szParam;
    		if( !m_Indexes.m_bMatchCase )
    			strName.MakeUpper();
     
    		return baseType::Validate<double, double>(strName.GetString(), pdblValue, dblMinValue, dblMaxValue, pContext);
    	}
     
    	ATL_NOINLINE DWORD Validate(
    		LPCSTR szParam,
    		LPSTR* ppszValue,
    		const ULONG nSize,
    		int nMinChars,
    		int nMaxChars,
    		CAksValidateContext* pContext = NULL) const throw()
    	{
    		if( !ppszValue || *ppszValue == NULL || nSize == 0)
    			return VALIDATION_E_FAIL;
     
    		CStringA strValue;
    		DWORD dwRet = Validate(szParam, &strValue, nMinChars, nMaxChars, pContext);
    		if(dwRet == VALIDATION_S_OK)
    		{
    			HRESULT hr = AssignString(*ppszValue, nSize, strValue, false);
    			if(hr == S_OK)
    				return VALIDATION_S_OK;
    			dwRet = VALIDATION_E_FAIL;
    		}
    		return dwRet;
    	}
     
    	ATL_NOINLINE DWORD ValidateString(
    		CStringA strParam, 
    		int nMinChars, 
    		int nMaxChars,
    		bool bAllowAlpha, 
    		bool bAllowNumeric, 
    		LPCSTR lpcszAdditional, 
    		int nFirstIsAlpha, 
    		CAksDataSet& dsFailureFlags,
    		CStringA strGenFailureParam,
    		CStringA strFailureParam) const throw()
    	{
    		CStringA strData;
    		DWORD dwRet = Validate(strParam, &strData, nMinChars, nMaxChars);
    		if ( dwRet != VALIDATION_S_OK ||
    			!IsParamValid(strParam, bAllowAlpha, bAllowNumeric, lpcszAdditional, nFirstIsAlpha))
    		{
    			if(dwRet == VALIDATION_S_OK)
    				dwRet = VALIDATION_E_INVALIDPARAM;
     
    			dsFailureFlags.AddValue(strGenFailureParam, true);
    			dsFailureFlags.AddValue(strFailureParam, true);
    			return dwRet;
    		}
    		dsFailureFlags.AddValue(strFailureParam, false);
    		return dwRet;
    	}
     
    	ATL_NOINLINE DWORD ValidateString(
    		CStringA strParam, 
    		int nMinChars, 
    		int nMaxChars, 
    		CAksDataSet& dsFailureFlags,
    		CStringA strGenFailureParam,
    		CStringA strFailureParam) const throw()
    	{
    		CStringA strData;
    		DWORD dwRet = Validate(strParam, &strData, nMinChars, nMaxChars);
    		if ( dwRet != VALIDATION_S_OK)
    		{
    			dsFailureFlags.AddValue(strGenFailureParam, true);
    			dsFailureFlags.AddValue(strFailureParam, true);
    			return dwRet;
    		}
    		dsFailureFlags.AddValue(strFailureParam, false);
    		return dwRet;
    	}
     
    	ATL_NOINLINE DWORD ValidateEmail(
    		CStringA strParam, 
    		LPCSTR lpcszAdditional, 
    		CAksDataSet& dsFailureFlags,
    		CStringA strGenFailureParam,
    		CStringA strFailureParam) const throw()
    	{
    		DWORD dwRet = ValidateString(
    			strParam, 
    			5, 
    			50,
    			true, 
    			true, 
    			lpcszAdditional, 
    			1, 
    			dsFailureFlags,
    			strGenFailureParam,
    			strFailureParam);
     
    		if(dwRet != VALIDATION_S_OK)
    			return dwRet;
     
    		CStringA strEmail;
    		dwRet = Exchange(strParam, &strEmail);
    		ATLASSERT(dwRet == VALIDATION_S_OK);
    		if(dwRet != VALIDATION_S_OK)
    		{
    			dsFailureFlags.AddValue(strGenFailureParam, true);
    			dsFailureFlags.AddValue(strFailureParam, true);
    			return dwRet;
    		}
     
    		int nIndex = -1;
     
    		if(	( (nIndex = strEmail.Find("@", 0)) == -1 ) || 
    			(  ++nIndex == strEmail.GetLength() ) ||
    			( (strEmail.Find("@", nIndex)) != -1 ) ||
    			( (nIndex = strEmail.Find(".", nIndex)) == -1 ) ||
    			( (strEmail.Find("@", 0) + 1) == nIndex) ||
    			(  ++nIndex == strEmail.GetLength() ) ||
    			( (strEmail.Find(".", nIndex)) != -1 ) )
    		{
    			dsFailureFlags.AddValue(strGenFailureParam, true);
    			dsFailureFlags.AddValue(strFailureParam, true);
    			return VALIDATION_E_FAIL;
    		}
    		dsFailureFlags.AddValue(strFailureParam, false);
    		return VALIDATION_S_OK;
    	}
     
    	ATL_NOINLINE bool ValidateEmail(
    		CStringA strEmailParam,
    		LPCSTR lpcszAdditional = "@._") const throw()
    	{
    		if(strEmailParam.IsEmpty())
    			return false;
     
    		AKS::CAksDataSet dsFailureFlags;
    		DWORD dwRet = ValidateEmail(
    			strEmailParam, 
    			lpcszAdditional, 
    			dsFailureFlags,
    			"Email_failure",
    			"failure");
    		return (dwRet == VALIDATION_S_OK)? true: false;
    	}
     
    	ATL_NOINLINE DWORD ValidateBool(
    		CStringA strParam, 
    		CAksDataSet& dsFailureFlags, 
    		CStringA strGenFailureParam,
    		CStringA strFailureParam) const throw()
    	{
    		LPCSTR szValue = Lookup(strParam);
    		if(szValue == NULL)
    		{
    			dsFailureFlags.AddValue(strGenFailureParam, true);
    			dsFailureFlags.AddValue(strFailureParam, true);
    			return VALIDATION_E_INVALIDPARAM;
    		}
    		dsFailureFlags.AddValue(strFailureParam, false);
    		return VALIDATION_S_OK;
    	}
     
    	ATL_NOINLINE DWORD ValidateDate(
    		CStringA strDateParam,
    		CStringA strDayParam, 
    		CStringA strMonthParam, 
    		CStringA strYearParam,
    		int nMinYear, 
    		int nMaxYear,
    		CAksDataSet& dsFailureFlags, 
    		CStringA strGenFailureParam,
    		CStringA strFailureParam) const throw()
    	{
    		int day = -1, month = -1, year = -1;
    		DWORD dwRet = VALIDATION_E_INVALIDPARAM;
    		if( (dwRet = Exchange(strDayParam, &day)) != VALIDATION_S_OK ||
    			(dwRet = Exchange(strMonthParam, &month)) != VALIDATION_S_OK ||
    			(dwRet = Exchange(strYearParam, &year)) != VALIDATION_S_OK)
    		{
    			dsFailureFlags.AddValue(strGenFailureParam, true);
    			dsFailureFlags.AddValue(strFailureParam, true);
    			return dwRet;
    		}
     
    		if(day <= 0 || day > 31 || month <= 0 || month > 12 || year < nMinYear || year > nMaxYear)
    		{
    			dsFailureFlags.AddValue(strGenFailureParam, true);
    			dsFailureFlags.AddValue(strFailureParam, true);
    			return VALIDATION_E_INVALIDPARAM;
    		}
     
    		if(month == 2)
    		{
    			if(year%4 != 0)
    			{
    				if(day > 28)
    				{
    					dsFailureFlags.AddValue(strGenFailureParam, true);
    					dsFailureFlags.AddValue(strFailureParam, true);
    					return VALIDATION_E_INVALIDPARAM;
    				}
    			}
    			else if(day > 29)
    			{
    				dsFailureFlags.AddValue(strGenFailureParam, true);
    				dsFailureFlags.AddValue(strFailureParam, true);
    				return VALIDATION_E_INVALIDPARAM;
    			}
    		}
    		else if(month == 4 || month == 6 || month == 9 || month == 11)
    		{
    			if(day > 30)
    			{
    				dsFailureFlags.AddValue(strGenFailureParam, true);
    				dsFailureFlags.AddValue(strFailureParam, true);
    				return VALIDATION_E_INVALIDPARAM;
    			}
    		}
    		dsFailureFlags.AddValue(strFailureParam, false);
    		return VALIDATION_S_OK;
    	}
     
    	template <class T>
    	ATL_NOINLINE DWORD ValidateNumber(
    		CStringA strParam,
    		T nMinValue,
    		T nMaxValue, 
    		CAksDataSet& dsFailureFlags,
    		CStringA strGenFailureParam,
    		CStringA strFailureParam) const throw()
    	 {
    		T Value;
    		DWORD dwRet = Validate(strParam, &Value, nMinValue, nMaxValue); 
    		if(dwRet != VALIDATION_S_OK)
    		{
    			dsFailureFlags.AddValue(strGenFailureParam, true);
    			dsFailureFlags.AddValue(strFailureParam, true);
    			return dwRet;
    		}
    		dsFailureFlags.AddValue(strFailureParam, false);
    		return dwRet;
    	 }
     
    	// operation in CAksDataSet
    public: 
    	CAksDataSet& operator=(const CAksDataSet& aDataSet) throw()  // affectation globale des ensembles de données
    	{
    		RemoveAll();
    		this->m_Indexes.m_bMatchCase = aDataSet.m_Indexes.m_bMatchCase;
    		return ((*this) += aDataSet);
    	}
     
    	ATL_NOINLINE CAksDataSet& operator+=(const CAksDataSet& aDataSet) throw()  // union des ensembles de données
    	{
    		ULONG nItem = aDataSet.GetCount();
    		for(ULONG iItem = 0; iItem < nItem; iItem++)
    		{
    			CStringA strName;
    			CStringA strValue;
    			bool bRet = aDataSet.LookupAt(iItem, strName, strValue);
    			ATLASSERT(bRet);
    			if(bRet)
    				AddValue(strName, strValue);
    		}
    		return (*this);
    	}
     
    	ATL_NOINLINE CAksDataSet& operator-=(const CAksDataSet& aDataSet) throw()  // soustraction des ensembles de données
    	{
    		ULONG nItem = aDataSet.GetCount();
    		for(ULONG iItem = 0; iItem < nItem; iItem++)
    		{
    			CStringA strName;
    			CStringA strValue;
    			bool bRet = aDataSet.LookupAt(iItem, strName, strValue);
    			ATLASSERT(bRet);
    			if(bRet)
    				RemoveData(strName);
    		}
    		return (*this);
    	}
     
    	ATL_NOINLINE CAksDataSet& operator&=(const CAksDataSet& aDataSet) throw()  // intersection des ensembles de données
    	{
    		CAksDataSet dsResult;
    		bool bSaveMatchValue = this->MatchCase();
    		dsResult.MatchCase(bSaveMatchValue);
    		this->MatchCase(bSaveMatchValue);
     
    		ULONG nItem = aDataSet.GetCount();
    		for(ULONG iItem = 0; iItem < nItem; iItem++)
    		{
    			CStringA strName;
    			CStringA strValue;
    			bool bRet = aDataSet.LookupAt(iItem, strName, strValue);
    			ATLASSERT(bRet);
    			if(bRet)
    			{
    				bRet = this->IsDataPresent(strName);
    				if(bRet)
    					dsResult.AddValue(strName, strValue);
    			}
    		}
    		*this = dsResult;
    		return (*this);
    	}
     
    	ATL_NOINLINE CAksDataSet& operator^=(const CAksDataSet& aDataSet) throw()  // l'union exclusif des ensembles de données
    	{
    		CAksDataSet dsUnion(*this);
    		CAksDataSet dsIntersection(*this);
    		dsUnion += aDataSet;
    		dsIntersection &= aDataSet;
    		*this = dsUnion - dsIntersection;
    		return (*this);
    	}
     
    	friend CAksDataSet operator+(const CAksDataSet& aDataSet1, const CAksDataSet& aDataSet2) // union des ensembles de données
    	{
    		CAksDataSet aDataSetResult = aDataSet1;
    		aDataSetResult += aDataSet2;
    		return aDataSetResult;
    	}
     
    	friend CAksDataSet operator-(const CAksDataSet& aDataSet1, const CAksDataSet& aDataSet2) // soustraction des ensembles de données
    	{
    		CAksDataSet aDataSetResult = aDataSet1;
    		aDataSetResult -= aDataSet2;
    		return aDataSetResult;
    	}
     
    	friend CAksDataSet operator&(const CAksDataSet& aDataSet1, const CAksDataSet& aDataSet2) // intersection des ensembles de données
    	{
    		CAksDataSet aDataSetResult = aDataSet1;
    		aDataSetResult &= aDataSet2;
    		return aDataSetResult;
    	}
     
    	friend CAksDataSet operator^(const CAksDataSet& aDataSet1, const CAksDataSet& aDataSet2)  // l'union exclusif des ensembles de données
    	{
    		CAksDataSet aDataSetResult = aDataSet1;
    		aDataSetResult ^= aDataSet2;
    		return aDataSetResult;
    	}
     
    	ATL_NOINLINE bool operator==(const CAksDataSet& aDataSet) const throw()  // équivalence des ensembles de données
    	{
    		ULONG nItem = aDataSet.GetCount();
    		if(this->GetCount() != nItem)
    			return false;
     
    		for(ULONG iItem = 0; iItem < nItem; iItem++)
    		{
    			CStringA strName;
    			CStringA strValue;
    			bool bRet = aDataSet.LookupAt(iItem, strName, strValue);
    			ATLASSERT(bRet);
    			if(bRet)
    			{
    				if( !this->IsDataPresent(strName) )
    					return false;
     
    				CStringA strThisValue = this->Lookup(strName);
    				if(strThisValue.CompareNoCase(strValue))
    					return false;
    			}
    		}
     
    		return true;
    	}
     
    	ATL_NOINLINE bool operator!=(const CAksDataSet& aDataSet) const throw()  // différence des ensembles de données
    	{
    		return !(*this == aDataSet);
    	}
     
    	// helpers
    public:
    	static CAksDataSet* CastToAksDataSet(VARIANT varDataSet)
    	{
    		return CCastingVariant<CAksDataSet>::CastFromVariant(varDataSet);
    	}
     
    	static VARIANT CastToVariant(CAksDataSet* pAksDataSet)
    	{
    		return CCastingVariant<CAksDataSet>::CastToVariant(pAksDataSet);
    	}
     
    	ATL_NOINLINE bool IsParamValid(
    		CStringA strParam, 
    		bool bAllowAlpha = true, 
    		bool bAllowNumeric = true, 
    		LPCSTR lpcszAdditional = NULL, 
    		int nFirstIsAlpha = 1) const throw()
    	{
    		_ATLTRY
    		{
    			CStringA strValue;
    			if(Exchange(strParam, &strValue) != VALIDATION_S_OK)
    				return false;
     
    			return IsStringValid(strValue.GetString(), bAllowAlpha, bAllowNumeric, lpcszAdditional, nFirstIsAlpha);
    		}
    		_ATLCATCHALL()
    		{
    			return false;
    		}
    	}
     
    	ATL_NOINLINE static bool IsStringValid(
    		LPCSTR lpcszString, 
    		bool bAllowAlpha = true, 
    		bool bAllowNumeric = true, 
    		LPCSTR lpcszAdditional = NULL, 
    		int nFirstIsAlpha = 1)
    	{
    		if (lpcszString == NULL)
    			return false;
     
    		int len = lstrlenA(lpcszString);
    		int len_additional = (lpcszAdditional == NULL)? 0: lstrlenA(lpcszAdditional);
    		int i = -1, j = -1;
     
    		if(bAllowAlpha && bAllowNumeric)
    		{
    			if(nFirstIsAlpha == 1)
    			{
    				if( (lpcszString[0] < 'A' || lpcszString[0] > 'Z') && (lpcszString[0] < 'a' || lpcszString[0] > 'z') )
    					return false;
    			}
    			else if(nFirstIsAlpha == 0)
    			{
    				if(lpcszString[0] < '0' || lpcszString[0] > '9')
    					return false;
    			}
    		}
     
    		 // le premier et le dernier caractère ne doivent pas être un espace
    		if(lpcszString[0] == ' ' || lpcszString[len-1] == ' ')
    			return false;
     
    		for (i = 0; i < len; i++)
    		{
    			if(bAllowAlpha)
    			{
    				if(lpcszString[i] >= 'A' && lpcszString[i] <= 'Z')
    					continue;
    				if(lpcszString[i] >= 'a' && lpcszString[i] <= 'z')
    					continue;
    			}
    			if(bAllowNumeric)
    			{
    				if(lpcszString[i] >= '0' && lpcszString[i] <= '9')
    					continue;
    			}
    			for (j = 0; j < len_additional; j++)
    			{
    				if (lpcszAdditional[j] == lpcszString[i])
    					break;
    			}
    			if (j >= len_additional)
    				break;
    		}
    		return (i < len) ? false : true;
    	}
     
    	ATL_NOINLINE static HRESULT AssignString(LPSTR pDataDest, const ULONG nSizeDest, LPCSTR pDataSrc, bool bTrunc)
    	{
    		if(pDataDest == NULL || pDataSrc == NULL || nSizeDest == 0)
    			return E_POINTER;
     
    		pDataDest[0] = '\0';
    		ULONG nLength = (ULONG) lstrlenA(pDataSrc);
    		if(nLength == 0)
    			return S_OK; // pDataSrc was empty so pDataDest will be empty!!!
     
    		if(nLength >= nSizeDest)
    		{
    			if( bTrunc )
    				nLength = nSizeDest - 1;
    			else
    				return E_FAIL;
    		}
     
    		if(nLength == 0)
    			return S_OK;
     
    		if(lstrcpynA(pDataDest, pDataSrc, nLength+1))
    		{
    			pDataDest[nLength] = '\0';
    			return S_OK;
    		}
     
    		return E_FAIL;
    	}
     
    	static HRESULT AssignString(BSTR* pbstrDataDest, LPCSTR pDataSrc)
    	{
    		if( !pbstrDataDest || !pDataSrc )
    			return E_POINTER;
     
    		CComBSTR bstr(pDataSrc);
    		return bstr.CopyTo(pbstrDataDest);
    	}
     
    	ATL_NOINLINE static HRESULT ConvertClsidToString(GUID guid, CStringA& strGuid)
    	{
    		CComBSTR bstrGuid(guid);
    		CStringA strTGuid(bstrGuid);
    		strGuid = strTGuid;
    		return S_OK;
    	}
     
    	ATL_NOINLINE static HRESULT ConvertClsidToString(GUID guid, BSTR* pbstrGuid)
    	{
    		if( !pbstrGuid )
    			return E_POINTER;
     
    		CComBSTR bstr(guid);
    		return bstr.CopyTo(pbstrGuid);
    	}
     
    	ATL_NOINLINE static HRESULT ConvertStringToClsid(CStringA strGuid, GUID* pGuid)
    	{
    		if(strGuid.IsEmpty() || pGuid == NULL)
    			return E_POINTER;
     
    		CStringW wstrGUID(strGuid);
    		if (FAILED(::CLSIDFromString(wstrGUID.GetBuffer(), pGuid)))
    			return E_FAIL;
    		wstrGUID.ReleaseBuffer();
    		return S_OK;
    	}
     
    	ATL_NOINLINE static HRESULT ConvertStringToClsid(BSTR bstrGuid, GUID* pGuid)
    	{
    		return ConvertStringToClsid(CStringA(bstrGuid), pGuid);
    	}
     
    	ATL_NOINLINE static bool TestResults(bool* pbResults, int nItem)
    	{
    		if( !pbResults  || nItem <= 0)
    			return false;
     
    		for(int iItem = 0; iItem < nItem; iItem++)
    		{
    			if( !pbResults[iItem] )
    				return false;
    		}
    		return true;
    	}
     
    	ATL_NOINLINE static bool TestResults(CAtlArray<bool>& aResultArray)
    	{
    		ULONG nCount = (ULONG) aResultArray.GetCount();
    		if(nCount == 0)
    			return false;
     
    		for(ULONG i = 0; i < nCount; i++)
    		{
    			if( !aResultArray[i] )
    				return false;
    		}
    		return true;
    	}
     
    	template<typename T>  // T = HRESULT or T = DWORD
    	ATL_NOINLINE static bool TestResults(T* pdwResults, int nItem, int nSuccessCode = 0)
    	{
    		if( !pdwResults  || nItem <= 0)
    			return false;
     
    		for(int iItem = 0; iItem < nItem; iItem++)
    		{
    			if( pdwResults[iItem] != nSuccessCode)
    				return false;
    		}
    		return true;
    	}
     
    private:
    	mapType m_Values;
    	simpleMapType m_Indexes;
    	ULONG m_Pos;
    };  // class CAksDataSet
     
    } // namespace AKS
    Rassure toi tu n'est pas obligé d'étudier toutes ces sources.
    Je te montrerai des exemples d'automation des 6 composants d'Excel, tu verras qu'ils sont très souples d'utilisation.

    Bon passons maintenant aux sources des 6 composants d'Excel
    Fais signe si tu es prêts.

  18. #18
    Membre émérite
    Avatar de Gabrielly
    Inscrit en
    Juin 2004
    Messages
    722
    Détails du profil
    Informations forums :
    Inscription : Juin 2004
    Messages : 722
    Par défaut
    Pour te mettre un peu au parfum voici un exemple
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
     
    // je commence avec l'objet application
    AKS::Automation::AksExcel::CAksExcelApp spExcelApp;  
     
    // mappe vers la bonne version
    HRESULT hr = spExcelApp.CreateInstance(EXCEL_APPLICATION);  // ici la version courante
    if (FAILED(hr))
    {
    	CString strError("Echec de chargement de Microsoft Excel");
    	return;
    }
     
    // je crée un classeur
    AKS::Automation::AksExcel::CAksWorkBook spWorkBook = spExcelApp.CreateWorkBook();  
    spWorkBook.SaveAs("C:\\fichier.xls");
     
    CString strFullName = spWorkBook.GetFullName();  // C:\\fichier.xls
     
    // j'ajoute une feuille
    AKS::Automation::AksExcel::CAksWorkSheet spWorkSheet = spWorkBook.CreateWorkSheet();  
    spWorkSheet.PutName("Test");
     
    // j'obtiens une rangée
    AKS::Automation::AksExcel::CAksRange spRange = spWorkSheet.GetRange("A1", "G10");  
     
    // Je définit une cellule
    spRange.PutItem(3, 4, "Salut");
     
    CString strText = spRange.GetItem(3, 4);  // Salut
    la suite
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
     
    AKS::Automation::AksExcel::CAksWorkBooks spWorkBooks = spExcelApp.GetWorkBookCollection();
    spWorkBook = spWorkBooks.GetItem("C:\\fichier.xls", true); // recherche par le nom complet
    spWorkBook.Show("Test"); // affiche le classeur avec la feuille Test par défaut
     
    AKS::Automation::AksExcel::CAksWorkSheets spWorkSheets = spWorkBook.GetWorkSheetCollection();
    spWorkSheet = spWorkSheets.GetItem("Test"); // recherche la feuille par son nom
     
    long nRows = 100;
    long nCols = 10
    spRange = spWorkSheet.GetRange("H12", nRows, nCols);  // une rangée de 100 lignes et 10 colonnes à partir de H12
     
    spRange.AutoFitColumns();  // ajustement automatique des colonnes
    AKS::Automation::AksExcel::CAksRange spColRange = spRange.GetColAt(4); // 4ième colonne
     
    double dValue = 14.3;
    long nRowFound = -1;
    long nColFound = -1;
    spColRange.FindData(dValue, nRowFound, nColFound); // cherche la valeur 14.3 dans cette colonne
     
    //...
    Dans le code suivant je remplis une listview à partir de CAksWorkSheet::LoadList() qui me masque tous les détails

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    // J'ouvre mon classeur à partir de l'objet application d'excel définit comme donnée membre dans l'objet application de mon CWinApp
    AKS::Automation::AksExcel::CAksWorkBook spTrunkRouteBook = pTheApp->m_spExcelApp.OpenWorkBook(pDoc->m_strTrunkRouteFile);
    		if( !spTrunkRouteBook )
    			return;
    
    // Je recherche la feuille "Sheet1" du classeur
    		AKS::Automation::AksExcel::CAksWorkSheet spTrunkRouteSheet = spTrunkRouteBook.OpenWorkSheet(_T("Sheet1"));
    		if( !spTrunkRouteSheet )
    		{
    			CString strMsg = _T("La feuille \"Sheet1\" du fichier \"");
    			strMsg += pDoc->m_strTrunkRouteFile;
    			strMsg += _T("\" est introuvable");
    
    			if (CTaskDialog::IsSupported())
    			{
    				CTaskDialog taskDialog(strMsg, _T("Erreur"), _T("Erreur de chargement du fichier excel"), TDCBF_OK_BUTTON);
    				taskDialog.SetMainIcon(TD_ERROR_ICON);
    				taskDialog.DoModal();
    			}
    			else
    			{
    			   	AfxMessageBox(strMsg, MB_ICONSTOP);
    			}
    
    			return;
    		}
    
    // J'obtiens la plus grande rangée non vide à partir de A1
    		AKS::Automation::AksExcel::CAksRange spTrunkRouteRange = spTrunkRouteSheet.GetLimitRangeAt(_T("A1"));
    
    // Chargement dynamique du CListCtrl
    		spTrunkRouteSheet.LoadList(spTrunkRouteRange, ThisListCtrl, true);
    		spTrunkRouteBook.Close();

  19. #19
    Membre confirmé
    Inscrit en
    Novembre 2010
    Messages
    176
    Détails du profil
    Informations forums :
    Inscription : Novembre 2010
    Messages : 176
    Par défaut
    bonsoir Gabrielly et tous les fans de ce thread !

    bon, je regarde tout çà... je m'applique à comprendre comment fonctionnent vos exemples ...

  20. #20
    Membre confirmé
    Inscrit en
    Novembre 2010
    Messages
    176
    Détails du profil
    Informations forums :
    Inscription : Novembre 2010
    Messages : 176
    Par défaut
    J’ai quelques petits soucis :

    Dans le header AskDataSet.h , les lignes :

    #include <atlcoll.h>
    #include <atlutil.h>

    Sont soulignées. Le nom de ces fichiers commence par ‘atl’ . Je bosse avec visual C++ 2010 express, tellement express qu’il n’a pas tous ces headers du genre pour ATL ou MFC. C’est cela ? Comment puis-je obtenir légalement + gratuitement (sacro-sainte gratuité !) ces deux fichiers ?

    Mais ce n’est peut-être pas le plus grave ….

    Dans plusieurs fichiers en tête, j’ai des éléments soulignés par visual.

    Par exemple, dans AksExcelApp, les ‘ : ‘ entre ‘CAksExcelApp’ et ‘public’ sont soulignées, au motif : « expected a ‘ :’ »
    Qu’est-ce qui ne va pas ?

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    class AFX_EXT_CLASS CAksExcelApp : public CAksComPtrT<Excel::_ApplicationPtr>
    Plus loin, c’est ‘public :’ qui est souligné au motif « expected a declaration »

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    public:
    void Close();
    void CloseAllUserExcelApp();
    void Quit();
    Comme AksExcelApp est un pilier de toute cette architecture de fichiers (on peut dire comme çà ?) , et bien je me retrouve avec tout plein de rouge dans le code pour mettre en œuvre les classes définies.

Discussions similaires

  1. Réponses: 4
    Dernier message: 05/12/2019, 13h16
  2. Réponses: 7
    Dernier message: 01/06/2013, 06h50
  3. Réponses: 0
    Dernier message: 13/05/2013, 16h21
  4. Faire fonctionner des objets d'Excel 2007 sur Excel 2003 ?
    Par brunoperel dans le forum Macros et VBA Excel
    Réponses: 5
    Dernier message: 08/12/2006, 20h52
  5. D'Excel à Access par Visual Basic 6.0
    Par moane dans le forum Macros et VBA Excel
    Réponses: 4
    Dernier message: 12/04/2006, 17h25

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo