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. #21
    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 n'ai pas encore fini
    Prend maintenant cette source de la classe CAksSafeArray à mettre dans le fichier AksSafeArray.cpp
    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
     
    // AksSafeArray.cpp : implementation file
    //
     
    #include "stdafx.h"
    #include "Aks.Excel.h"
    #include "AksSafeArray.h"
     
    // CAksSafeArray
    using namespace AKS::Utility;
     
     
    CAksSafeArray::CAksSafeArray()
    			:COleSafeArray()
    {
     
    }
    CAksSafeArray::CAksSafeArray(const SAFEARRAY& saSrc, VARTYPE vtSrc)
    			:COleSafeArray(saSrc, vtSrc)
    {
     
    }
     
    CAksSafeArray::CAksSafeArray(LPCSAFEARRAY pSrc, VARTYPE vtSrc)
    			:COleSafeArray(pSrc, vtSrc)
    {
     
    }
     
    CAksSafeArray::CAksSafeArray(const COleSafeArray& saSrc)
    			:COleSafeArray(saSrc)
    {
     
    }
     
    CAksSafeArray::CAksSafeArray(const CAksSafeArray& saSrc)
    			:COleSafeArray(saSrc)
    {
     
    }
     
    CAksSafeArray::CAksSafeArray(const VARIANT& varSrc)
    			:COleSafeArray(varSrc)
    {
     
    }
     
    CAksSafeArray::CAksSafeArray(LPCVARIANT pSrc)
    			:COleSafeArray(pSrc)
    {
     
    }
     
    CAksSafeArray::CAksSafeArray(const COleVariant& varSrc)
    			:COleSafeArray(varSrc)
    {
     
    }
     
    void CAksSafeArray::FillSafeArray(long nIndex, CStringA str)
    {
    	long index[1];
    	index[0] = nIndex;
    	CComBSTR bstr(str);
    	PutElement(index, bstr.m_str);
    }
     
    void CAksSafeArray::FillSafeArray(long nIndex, long nValue)
    {
    	long index[1];
    	index[0] = nIndex;
    	PutElement(index, &nValue);
    }
     
    void CAksSafeArray::FillSafeArray(long nIndex, double dValue)
    {
    	long index[1];
    	index[0] = nIndex;
    	PutElement(index, &dValue);
    }
     
    void CAksSafeArray::FillSafeArray(AKS::CAksDataSet dsValueSet)
    {
    	FillSafeArrayValues(dsValueSet);
    }
     
    void CAksSafeArray::FillSafeArrayValues(AKS::CAksDataSet dsValueSet)
    {
    	DWORD dwDim = GetDim();
    	ATLASSERT(dwDim == 1);
    	if(dwDim != 1)
    		return;
     
    	long nUpperBound = 0;
    	GetUBound(1, &nUpperBound);
     
    	long nLowerBound = 0;
    	GetLBound(1, &nLowerBound);
     
    	POSITION pos = dsValueSet.GetFirstPosition();
    	for(long nIndex = nLowerBound; nIndex <= nUpperBound; nIndex++)
    	{
    		if(pos == NULL)
    			return;
     
    		CStringA strKey;
    		CStringA strValue;
    		dsValueSet.GetNext(pos, strKey, strValue);
    		if( (vt & VT_BSTR) == VT_BSTR )
    		{
    			FillSafeArray(nIndex, strValue);
    		}
    		else if( (vt & VT_R8) == VT_R8 )
    		{
    			double dValue = 0;
    			DWORD dwRet = dsValueSet.Exchange(strKey, &dValue);
    			if(VALIDATION_SUCCEEDED(dwRet))
    				FillSafeArray(nIndex, dValue);
    		}
    		else if( (vt & VT_I4) == VT_I4 )
    		{
    			long lValue = 0;
    			DWORD dwRet = dsValueSet.Exchange(strKey, &lValue);
    			if(VALIDATION_SUCCEEDED(dwRet))
    				FillSafeArray(nIndex, lValue);
    		}
    	}
    }
     
    void CAksSafeArray::FillSafeArrayKeys(AKS::CAksDataSet dsKeySet)
    {
    	DWORD dwDim = GetDim();
    	ATLASSERT(dwDim == 1);
    	if(dwDim != 1)
    		return;
     
    	long nUpperBound = 0;
    	GetUBound(1, &nUpperBound);
     
    	long nLowerBound = 0;
    	GetLBound(1, &nLowerBound);
     
    	POSITION pos = dsKeySet.GetFirstPosition();
    	for(long nIndex = nLowerBound; nIndex <= nUpperBound; nIndex++)
    	{
    		if(pos == NULL)
    			return;
     
    		CStringA strKey;
    		CStringA strValue;
    		dsKeySet.GetNext(pos, strKey, strValue);
    		if( (vt & VT_BSTR) == VT_BSTR )
    		{
    			FillSafeArray(nIndex, strKey);
    		}
    		else if( (vt & VT_R8) == VT_R8 )
    		{
    			double dValue = 0;
    			DWORD dwRet = dsKeySet.ConvertNumber(strKey, &dValue);
    			if(VALIDATION_SUCCEEDED(dwRet))
    				FillSafeArray(nIndex, dValue);
    		}
    		else if( (vt & VT_I4) == VT_I4 )
    		{
    			long lValue = 0;
    			DWORD dwRet = dsKeySet.ConvertNumber(strKey, &lValue);
    			if(VALIDATION_SUCCEEDED(dwRet))
    				FillSafeArray(nIndex, lValue);
    		}
    	}
    }
     
    void CAksSafeArray::FillSafeMatrix(long iRow, long iCol, CStringA str)
    {
    	long index[2];
    	index[0] = iRow;
    	index[1] = iCol;
    	CComBSTR bstr(str);
    	PutElement(index, bstr.m_str);
    }
     
    void CAksSafeArray::FillSafeMatrix(long iRow, long iCol, long nValue)
    {
    	long index[2];
    	index[0] = iRow;
    	index[1] = iCol;
    	PutElement(index, &nValue);
    }
     
    void CAksSafeArray::FillSafeMatrix(long iRow, long iCol, double dValue)
    {
    	long index[2];
    	index[0] = iRow;
    	index[1] = iCol;
    	PutElement(index, &dValue);
    }
     
    void CAksSafeArray::FillSafeMatrix(AKS::CAksDataSet dsValueSet)
    {
    	DWORD dwDim = GetDim();
    	ATLASSERT(dwDim == 2);
    	if(dwDim != 2)
    		return;
     
    	long nUpperRowBound = 0;
    	long nUpperColBound = 0;
    	GetUBound(1, &nUpperRowBound);
    	GetUBound(2, &nUpperColBound);
     
    	long nLowerRowBound = 0;
    	long nLowerColBound = 0;
    	GetLBound(1, &nLowerRowBound);
    	GetLBound(2, &nLowerColBound);
     
    	POSITION pos = dsValueSet.GetFirstPosition();
    	for(long nRow = nLowerRowBound;nRow <= nUpperRowBound; nRow++)
    	{
    		for(long nCol = nLowerColBound; nCol <= nUpperColBound; nCol++)
    		{
    			if(pos == NULL)
    				return;
     
    			CStringA strKey;
    			CStringA strValue;
    			dsValueSet.GetNext(pos, strKey, strValue);
    			if( (vt & VT_BSTR) == VT_BSTR )
    			{
    				FillSafeMatrix(nRow, nCol, strValue);
    			}
    			else if( (vt & VT_R8) == VT_R8 )
    			{
    				double dValue = 0;
    				DWORD dwRet = dsValueSet.Exchange(strKey, &dValue);
    				if(VALIDATION_SUCCEEDED(dwRet))
    					FillSafeMatrix(nRow, nCol, dValue);
    			}
    			else if( (vt & VT_I4) == VT_I4 )
    			{
    				long lValue = 0;
    				DWORD dwRet = dsValueSet.Exchange(strKey, &lValue);
    				if(VALIDATION_SUCCEEDED(dwRet))
    					FillSafeMatrix(nRow, nCol, lValue);
    			}
    		}
    	}
    }
     
    void CAksSafeArray::FillSafeCube(long iRow, long iCol, long iHeight, CStringA str)
    {
    	long index[3];
    	index[0] = iRow;
    	index[1] = iCol;
    	index[2] = iHeight;
    	CComBSTR bstr(str);
    	PutElement(index, bstr.m_str);
    }
     
    void CAksSafeArray::FillSafeCube(long iRow, long iCol, long iHeight, long nValue)
    {
    	long index[3];
    	index[0] = iRow;
    	index[1] = iCol;
    	index[2] = iHeight;
    	PutElement(index, &nValue);
    }
     
    void CAksSafeArray::FillSafeCube(long iRow, long iCol, long iHeight, double dValue)
    {
    	long index[3];
    	index[0] = iRow;
    	index[1] = iCol;
    	index[2] = iHeight;
    	PutElement(index, &dValue);
    }
     
    void CAksSafeArray::FillSafeCube(AKS::CAksDataSet dsValueSet)
    {
    	DWORD dwDim = GetDim();
    	ATLASSERT(dwDim == 3);
    	if(dwDim != 3)
    		return;
     
    	long nUpperRowBound = 0;
    	long nUpperColBound = 0;
    	long nUpperHeightBound = 0;
    	GetUBound(1, &nUpperRowBound);
    	GetUBound(2, &nUpperColBound);
    	GetUBound(3, &nUpperHeightBound);
     
    	long nLowerRowBound = 0;
    	long nLowerColBound = 0;
    	long nLowerHeightBound = 0;
    	GetLBound(1, &nLowerRowBound);
    	GetLBound(2, &nLowerColBound);
    	GetLBound(3, &nLowerHeightBound);
     
    	POSITION pos = dsValueSet.GetFirstPosition();
    	for(long nRow = nLowerRowBound;nRow <= nUpperRowBound; nRow++)
    	{
    		for(long nCol = nLowerColBound; nCol <= nUpperColBound; nCol++)
    		{
    			for(long nHeight = nLowerHeightBound; nHeight <= nUpperHeightBound; nHeight++)
    			{
    				if(pos == NULL)
    					return;
     
    				CStringA strKey;
    				CStringA strValue;
    				dsValueSet.GetNext(pos, strKey, strValue);
    				if( (vt & VT_BSTR) == VT_BSTR )
    				{
    					FillSafeCube(nRow, nCol, nHeight, strValue);
    				}
    				else if( (vt & VT_R8) == VT_R8 )
    				{
    					double dValue = 0;
    					DWORD dwRet = dsValueSet.Exchange(strKey, &dValue);
    					if(VALIDATION_SUCCEEDED(dwRet))
    						FillSafeCube(nRow, nCol, nHeight, dValue);
    				}
    				else if( (vt & VT_I4) == VT_I4 )
    				{ 
    					long lValue = 0;
    					DWORD dwRet = dsValueSet.Exchange(strKey, &lValue);
    					if(VALIDATION_SUCCEEDED(dwRet))
    						FillSafeCube(nRow, nCol, nHeight, lValue);
    				}
    			}
    		}
    	}
    }
    ensuite

  2. #22
    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
    L'implémentation de la CAksExcelApp dans le fichier AksExcelApp.cpp
    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
     
    #include "stdafx.h"
    #include "Aks.Excel.h"
    #include "AksExcelApp.h"
     
    using namespace AKS::Automation::AksExcel;
     
    ATL::CCriticalSection g_cs;
     
    HRESULT CAksExcelApp::CreateInstance(const CLSID& rclsid) throw()
    {
    	return baseType::CreateInstance(rclsid, NULL, CLSCTX_SERVER);
    }
     
    HRESULT CAksExcelApp::CreateInstance(LPCWSTR clsidString) throw()
    {
    	return baseType::CreateInstance(clsidString, NULL, CLSCTX_SERVER);
    }
     
    HRESULT CAksExcelApp::CreateInstance(LPCSTR clsidStringA) throw()
    {
    	return baseType::CreateInstance(clsidStringA, NULL, CLSCTX_SERVER);
    }
     
    Excel::_WorkbookPtr CAksExcelApp::CreateWorkBook()
    {
    	Excel::WorkbooksPtr spWorkbooks = ((baseType)this)->GetWorkbooks();
    	return spWorkbooks->Add(Excel::xlWorksheet);
    }
     
    Excel::_WorkbookPtr CAksExcelApp::OpenWorkBook(CString strFileName)
    {
    	if( !::PathFileExists(strFileName) )
    		return NULL;
     
    	Excel::WorkbooksPtr spWorkbooks = ((baseType)this)->GetWorkbooks();
    	return spWorkbooks->_Open(strFileName.GetString());
    }
     
    Excel::_WorkbookPtr CAksExcelApp::OpenWorkBook(CString strFileName, CString strPassword)
    {
    	if( !::PathFileExists(strFileName) )
    		return NULL;
     
    	Excel::WorkbooksPtr spWorkbooks = ((baseType)this)->GetWorkbooks();
    	return spWorkbooks->_Open(
    		strFileName.GetString(),			// FileName
    		2,									// UpdateLinks, never update link
    		false,								// ReadOnly
    		5,									// Format, no format apply only for openning text file
    		strPassword.GetString(),			// Password, 
    		strPassword.GetString());			// WriteResPassword
    }
     
    Excel::_WorkbookPtr CAksExcelApp::GetActiveWorkBook()
    {
    	return ((baseType)this)->GetActiveWorkbook();
    }
     
    HWND CAksExcelApp::GetHwnd()
    {
    	long lhWnd = ((baseType)this)->GetHwnd();
    #pragma warning ( disable: 4312)
    	HWND hWnd = (HWND) lhWnd;
    #pragma warning ( default: 4312)
    	return hWnd;
    }
     
    HINSTANCE CAksExcelApp::GetHinstance()
    {
    	long lhInstance = ((baseType)this)->GetHinstance();
    #pragma warning ( disable: 4312)
    	HINSTANCE hInstance = (HINSTANCE) lhInstance;
    #pragma warning ( default: 4312)
    	return hInstance;
    }
     
    CString CAksExcelApp::GetPath()
    {
    	_bstr_t bstrPath = ((baseType)this)->GetPath();
    	return CString(bstrPath.GetBSTR());
    }
     
    // True if the application is visible or if it was created or started by the user. 
    // False if you created or started the application programmatically by using the 
    // CreateObject or GetObject functions and the application is hidden.
    // When the UserControl property is False for an object, 
    // that object is released when the last programmatic reference to the object is released. 
    // If this property is False, Microsoft Excel quits when the last object in the session is 
    // released.
     
    bool CAksExcelApp::GetUserControl()
    {
    	VARIANT_BOOL bUserCtrl = ((baseType)this)->GetUserControl();
    	return bUserCtrl? true: false;
    }
     
    void CAksExcelApp::PutUserControl(bool bUserCtrl)
    {
    	VARIANT_BOOL bRhs = bUserCtrl? VARIANT_TRUE: VARIANT_FALSE;
    	((baseType)this)->PutUserControl(bRhs);
    }
     
    bool CAksExcelApp::GetVisible()
    {
    	VARIANT_BOOL bVisible = ((baseType)this)->GetVisible();
    	return bVisible? true: false;
    }
     
    void CAksExcelApp::PutVisible(bool bVisible)
    {
    	VARIANT_BOOL bRhs = bVisible? VARIANT_TRUE: VARIANT_FALSE;
    	((baseType)this)->PutVisible(0, bRhs);
    }
     
    void CAksExcelApp::Close()
    {
    	CAksWorkBooks spWorkBooks = GetWorkBookCollection();
    	spWorkBooks.Close();
     
    	long lhWnd = 0;
    	((baseType)this)->get_Hwnd(&lhWnd);
    #pragma warning ( disable: 4312)
    	HWND hWnd = (HWND) lhWnd;
    #pragma warning ( default: 4312)
    	::PostMessage(hWnd, WM_CLOSE, 0, 0);
    }
     
    void CAksExcelApp::Quit()
    {
    	((baseType)this)->Quit();
    }
     
    void CAksExcelApp::CloseAllUserExcelApp()
    {
    	g_cs.Enter();  // parce que une autre instance peut affecter le z-order modifier par celui-ci
     
    	CWaitCursor wait;
    	HWND hThisWnd = GetHwnd();
    	ATLASSERT(hThisWnd);
    	if(hThisWnd == NULL)
    		return;
    	int nTour = 0;
    	int nMaxTour = 2;
    	do
    	{
    		CWnd* pWnd = CWnd::FindWindow(_T("XLMAIN"), NULL);
    		if(pWnd == NULL)
    			break;
     
    		HWND hOtherWnd = pWnd->GetSafeHwnd();
    		if(hThisWnd == hOtherWnd)
    		{
    			pWnd->SetWindowPos(&CWnd::wndBottom, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE);
    			if(nTour++ == nMaxTour)
    				break;
    		}
    		else if(nTour == 0)
    			pWnd->SetWindowPos(&CWnd::wndBottom, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE);
    		else if( nTour >= 1 && pWnd->IsWindowVisible() )
    		{
    			if(nTour >= 2)
    			{
    				if(nTour == nMaxTour)
    					nMaxTour = nTour + 1;
     
    				pWnd->SetActiveWindow();
    				CString strTitle;
    				pWnd->GetWindowText(strTitle);
    				CString strMsg = _T("Veuillez fermer la fenêtre Microsoft Excel : \n\"");
    				strMsg += strTitle;
    				strMsg += _T("\"");
    				AfxMessageBox(strMsg);
    				Sleep(5000);
    				continue;
    			}
    			else
    			{
    				pWnd->SetWindowPos(&CWnd::wndBottom, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE);
    				pWnd->PostMessage(WM_CLOSE);
    				Sleep(2000);
    			}
    		}
    		else
    			pWnd->SetWindowPos(&CWnd::wndBottom, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE);
    	}
    	while(1);
     
    	Sleep(2000);
    	g_cs.Leave();
    }
     
    CAksWorkBooks CAksExcelApp::GetWorkBookCollection()
    {
    	return ((baseType)this)->GetWorkbooks();
    }
     
    CString CAksExcelApp::GetVersion()
    {
    	_bstr_t bstrVersion = ((baseType)this)->GetVersion();
    	return CString(bstrVersion.GetBSTR());
    }

  3. #23
    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
    L'implémentation de la CAksWorkBooks dans le fichier AksWorkBooks.cpp

    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
     
    #include "stdafx.h"
    #include "Aks.Excel.h"
    #include "AksWorkBooks.h"
     
    using namespace AKS::Automation::AksExcel;
     
    IDispatchPtr CAksWorkBooks::GetItem(long nItemIndex)
    {
    	if(nItemIndex <= 0)
    		return NULL;
    	long nCount = ((baseType)this)->GetCount();
    	if(nItemIndex <= nCount)
    		return ((baseType)this)->GetItem(nItemIndex);
    	return NULL;
    }
     
     
    IDispatchPtr CAksWorkBooks::GetItem(CString strItemName, bool bFullName)
    {
    	long nCount = ((baseType)this)->GetCount();
    	for(long nIndex = 1; nIndex <= nCount; nIndex++)
    	{
    		CAksWorkBook spWorkBook = ((baseType)this)->GetItem(nIndex);
    		CString strWorkBookName;
    		if(bFullName)
    			strWorkBookName = spWorkBook.GetFullName();
    		else
    			strWorkBookName = spWorkBook.GetName();
    		if(strItemName.CompareNoCase(strWorkBookName) == 0)
    			return spWorkBook;
    	}
    	return NULL;
    }
     
    CString CAksWorkBooks::GetWorkBookName(long nItemIndex, bool bFullName)
    {
    	CString strWorkBookName;
    	CAksWorkBook spWorkBook = GetItem(nItemIndex);
    	if(spWorkBook)
    	{
    		if(bFullName)
    			strWorkBookName = spWorkBook.GetFullName();
    		else
    			strWorkBookName = spWorkBook.GetName();
    	}
    	return strWorkBookName;
    }
     
    long CAksWorkBooks::GetWorkBookIndex(CString strItemName, bool bFullName)
    {
    	long nCount = ((baseType)this)->GetCount();
    	for(long nIndex = 1; nIndex <= nCount; nIndex++)
    	{
    		CAksWorkBook spWorkBook = ((baseType)this)->GetItem(nIndex);
    		CString strWorkBookName;
    		if(bFullName)
    			strWorkBookName = spWorkBook.GetFullName();
    		else
    			strWorkBookName = spWorkBook.GetName();
    		if(strItemName.CompareNoCase(strWorkBookName) == 0)
    			return nIndex;
    	}
    	return 0;
    }
     
    long CAksWorkBooks::GetWorkBookCount()
    {
    	long nCount = ((baseType)this)->GetCount();
    	return nCount;
    }
     
    POSITION CAksWorkBooks::GetFirstWorkBookPosition()
    {
    	long nCount = ((baseType)this)->GetCount();
    	if(nCount == 0)
    		return NULL;
     
    	m_Pos = 1;
    	return (POSITION) &m_Pos;
    }
     
    IDispatchPtr CAksWorkBooks::GetNextWorkBook(POSITION& pos)
    {
    	if( !pos )
    		return NULL;
     
    	long* pnIndex = (long*) pos;
    	ATLASSERT(pnIndex);
     
    	if( !pnIndex || *pnIndex < 1 )
    		return NULL;
     
    	CAksWorkBook spWorkBook;
     
    	long nCount = ((baseType)this)->GetCount();
    	if( *pnIndex <= nCount )
    	{
    		spWorkBook = ((baseType)this)->GetItem(*pnIndex);
    		ATLASSERT(spWorkBook);
    		(*pnIndex)++;
    	}
     
    	if(*pnIndex > nCount)
    		pos = NULL;
     
    	return spWorkBook;
    }
     
    HRESULT CAksWorkBooks::Close()
    {
    	long nCount = ((baseType)this)->GetCount();
    	for(int iItem = 1; iItem <= nCount; iItem++)
    	{
    		CAksWorkBook spWorkBook = ((baseType)this)->GetItem(iItem);
    		if(spWorkBook)
    			spWorkBook.Close();
    	}
    	return ((baseType)this)->Close();
    }

  4. #24
    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
    L'implémentation de la CAksWorkBook dans le fichier AksWorkBook.cpp

    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
     
    #include "stdafx.h"
    #include "Aks.Excel.h"
    #include "AksWorkBook.h"
     
    using namespace AKS::Automation::AksExcel;
     
    IDispatchPtr CAksWorkBook::CreateWorkSheet()
    {
    	CAksWorkSheets spWorksheets = ((baseType)this)->GetSheets();
    	return spWorksheets->Add();
    }
     
    IDispatchPtr CAksWorkBook::OpenWorkSheet(CString strName)
    {
    	CAksWorkSheets spWorksheets = ((baseType)this)->GetSheets();
    	return spWorksheets.GetItem(strName);
    }
     
    IDispatchPtr CAksWorkBook::OpenWorkSheet(long nIndex)
    {
    	CAksWorkSheets spWorksheets = ((baseType)this)->GetSheets();
    	return spWorksheets.GetItem(nIndex);
    }
     
    bool CAksWorkBook::Show(LPCTSTR pszWorkSheetName)
    {
    	CAksExcelApp spExcelApp = ((baseType)this)->GetApplication();
    	CAksWorkSheet spWorkSheet;
     
    	CString strWorkSheetName = pszWorkSheetName;
    	if(strWorkSheetName.IsEmpty())
    		spWorkSheet = ((baseType)this)->GetActiveSheet();
    	else
    		spWorkSheet = OpenWorkSheet(strWorkSheetName);
     
    	if(spWorkSheet == NULL)
    		return false;
     
    	spWorkSheet->Select();
    	spExcelApp->PutVisible(0, TRUE);
    	spExcelApp->PutUserControl(TRUE);
    	return true;
    }
     
    bool CAksWorkBook::Show(long nWorkSheetIndex)
    {
    	if(nWorkSheetIndex <= 0)
    		return Show((LPCTSTR)NULL);
     
    	CAksExcelApp spExcelApp = ((baseType)this)->GetApplication();
    	CAksWorkSheet spWorkSheet = OpenWorkSheet(nWorkSheetIndex);
    	if(spWorkSheet == NULL)
    		return false;
     
    	spWorkSheet->Select();
    	spExcelApp->PutVisible(0, TRUE);
    	spExcelApp->PutUserControl(TRUE);
    	return true;
    }
     
    HRESULT CAksWorkBook::SaveAs(CString strXlFile, short XlAccessMode)
    {
    	if(strXlFile.IsEmpty())
    		return E_POINTER;
     
    	HRESULT hr = ((baseType)this)->_SaveAs(
    			strXlFile.GetString(),										// Filename
    			Excel::xlWorkbookNormal,									// FileFormat
    			"",															// Password
    			"",															// WriteResPassword
    			false,														// ReadOnlyRecommended
    			false,														// CreateBackup
    			(Excel::XlSaveAsAccessMode) XlAccessMode,					// AccessMode
    			(Excel::XlSaveConflictResolution) Excel::xlLocalSessionChanges);	// ConflictResolution								// ConflictResolution
     
    	return hr;
    }
     
    HRESULT CAksWorkBook::SaveAs(
    		CString strXlFile, 
    		CString strPassword, 
    		CString strWriteResPassword,
    		bool bReadOnly, 
    		short XlAccessMode)
    {
    	if(strXlFile.IsEmpty())
    		return E_POINTER;
     
    	HRESULT hr = ((baseType)this)->_SaveAs(
    			strXlFile.GetString(),									// Filename
    			Excel::xlWorkbookNormal,								// FileFormat
    			strPassword.GetString(),								// Password
    			strWriteResPassword.GetString(),						// WriteResPassword
    			bReadOnly,												// ReadOnlyRecommended
    			false,													// CreateBackup
    			(Excel::XlSaveAsAccessMode) XlAccessMode,					// AccessMode
    			(Excel::XlSaveConflictResolution) Excel::xlLocalSessionChanges);	// ConflictResolution
     
    	return hr;
    }
     
    HRESULT CAksWorkBook::Save()
    {
    	return ((baseType)this)->Save();
    }
     
    HRESULT CAksWorkBook::SaveCopyAs(CString strXlFile)
    {
    	if(strXlFile.IsEmpty())
    		return E_POINTER;
     
    	return ((baseType)this)->SaveCopyAs(strXlFile.GetString());
    }
     
    CString CAksWorkBook::GetName(void)
    {
    	CString strName =((baseType)this)->GetName();
    	return strName;
    }
     
    CString CAksWorkBook::GetFullName(void)
    {
    	CString strFullName =((baseType)this)->GetFullName();
    	return strFullName;
    }
     
     
    void CAksWorkBook::Close(bool bSaveChange)
    {
    	((baseType)this)->Close(bSaveChange);
    }
     
    /*
    enum XlSaveConflictResolution
    {
        xlLocalSessionChanges = 2,
        xlOtherSessionChanges = 3,
        xlUserResolution = 1
    };
    */
     
    Excel::XlSaveConflictResolution CAksWorkBook::GetConflictResolution()
    {
    	return ((baseType)this)->GetConflictResolution();
    }
     
    void CAksWorkBook::PutConflictResolution(Excel::XlSaveConflictResolution RHS)
    {
    	 ((baseType)this)->PutConflictResolution(RHS);
    }
     
    CAksWorkSheets CAksWorkBook::GetWorkSheetCollection()
    {
    	return ((baseType)this)->GetSheets();
    }
     
    bool CAksWorkBook::HasPassword()
    {
    	VARIANT_BOOL bHasPwd = ((baseType)this)->GetHasPassword();
    	return bHasPwd? true: false;
    }
     
    CString CAksWorkBook::GetPassword()
    {
    	CString strPassword = ((baseType)this)->GetPassword();
    	return strPassword;
    }
     
    void CAksWorkBook::SetPassword(CString strPassword)
    {
    	((baseType)this)->PutPassword(strPassword.GetString());
    }
     
    CString CAksWorkBook::GetWritePassword()
    {
    	CString strWritePassword = ((baseType)this)->GetWritePassword();
    	return strWritePassword;
    }
     
    void CAksWorkBook::SetWritePassword(CString strWritePassword)
    {
    	((baseType)this)->PutWritePassword(strWritePassword.GetString());
    }
     
    CString CAksWorkBook::GetPasswordEncryptionProvider()
    {
    	CString strPwdEncryProv = ((baseType)this)->GetPasswordEncryptionProvider();
    	return strPwdEncryProv;
    }
     
    CString CAksWorkBook::GetPasswordEncryptionAlgorithm()
    {
    	CString strPwdEncryAlgo = ((baseType)this)->GetPasswordEncryptionAlgorithm();
    	return strPwdEncryAlgo;
    }
     
    long CAksWorkBook::GetPasswordEncryptionKeyLength()
    {
    	return ((baseType)this)->GetPasswordEncryptionKeyLength();
    }
     
    bool CAksWorkBook::GetPasswordEncryptionFileProperties()
    {
    	VARIANT_BOOL bPwdEncryFileProp = ((baseType)this)->GetPasswordEncryptionFileProperties();
    	return bPwdEncryFileProp? true: false;
    }
     
    HRESULT CAksWorkBook::SetPasswordEncryptionOptions(
    	LPCTSTR pszPwdEncryProv,
    	LPCTSTR pszPwdEncryAlgo,
    	long nPwdEncryKeyLen,
    	bool bPwdEncryFileProp)
    {
    	CString strPwdEncryProv;
    	if(pszPwdEncryProv == NULL)
    		strPwdEncryProv = "Microsoft RSA SChannel Cryptographic Provider";
     
    	CString strPwdEncryAlgo;
    	if(pszPwdEncryAlgo == NULL)
    		strPwdEncryAlgo = "RC4";
     
    	if(nPwdEncryKeyLen == 0)
    		nPwdEncryKeyLen = 128;
     
    	return ((baseType)this)->SetPasswordEncryptionOptions(
    		strPwdEncryProv.GetString(),
            strPwdEncryAlgo.GetString(),
            nPwdEncryKeyLen,
            bPwdEncryFileProp);
    }
     
    bool CAksWorkBook::GetReadOnlyRecommended()
    {
    	VARIANT_BOOL bReadOnlyRecommended = ((baseType)this)->GetReadOnlyRecommended();
    	return bReadOnlyRecommended? true: false;
    }
     
    void CAksWorkBook::SetReadOnlyRecommended(bool bReadOnlyRecommended)
    {
    	VARIANT_BOOL bRhs = bReadOnlyRecommended? VARIANT_TRUE: VARIANT_FALSE;
    	((baseType)this)->PutReadOnlyRecommended(bRhs);
    }
     
    HRESULT CAksWorkBook::Protect(CString strPassword, bool bSheets, bool bWindows)
    {
    	return ((baseType)this)->_Protect(strPassword.GetString(), bSheets, bWindows);
    }
     
    HRESULT CAksWorkBook::ProtectSharing(
    	CString strFilename, 
    	CString strPassword, 
    	CString strWriteResPassword,
    	bool bReadOnlyRecommended,
    	bool bCreateBackup,
    	CString strSharingPassword)
    {
    	return ((baseType)this)->ProtectSharing (
    		strFilename.GetString(),
            strPassword.GetString(),
            strWriteResPassword.GetString(),
            bReadOnlyRecommended,
            bCreateBackup,
    		strSharingPassword.GetString());
    }
     
    HRESULT CAksWorkBook::Unprotect(CString strPassword)
    {
    	return ((baseType)this)->Unprotect(strPassword.GetString(), 0);
    }
     
    HRESULT CAksWorkBook::UnprotectSharing(CString strSharingPassword)
    {
    	return ((baseType)this)->UnprotectSharing(strSharingPassword.GetString());
    }

  5. #25
    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
    L'implémentation de la CAksWorkSheets dans le fichier AksWorkSheets.cpp

    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
     
    #include "stdafx.h"
    #include "Aks.Excel.h"
    #include "AksWorkSheets.h"
     
    using namespace AKS::Automation::AksExcel;
     
    IDispatchPtr CAksWorkSheets::GetItem(long nItemIndex)
    {
    	if(nItemIndex <= 0)
    		return NULL;
    	long nCount = ((baseType)this)->GetCount();
    	if(nItemIndex <= nCount)
    		return ((baseType)this)->GetItem(nItemIndex);
    	return NULL;
    }
     
     
    IDispatchPtr CAksWorkSheets::GetItem(CString strItemName)
    {
    	long nCount = ((baseType)this)->GetCount();
    	for(long nIndex = 1; nIndex <= nCount; nIndex++)
    	{
    		CAksWorkSheet spWorkSheet = ((baseType)this)->GetItem(nIndex);
    		CString strSheetName = spWorkSheet.GetName();
    		if(strItemName.CompareNoCase(strSheetName) == 0)
    			return spWorkSheet;
    	}
    	return NULL;
    }
     
    CString CAksWorkSheets::GetWorkSheetName(long nItemIndex)
    {
    	CString strName;
    	CAksWorkSheet spWorkSheet = GetItem(nItemIndex);
    	if(spWorkSheet)
    		strName = spWorkSheet.GetName();
    	return strName;
    }
     
    long CAksWorkSheets::GetWorkSheetIndex(CString strItemName)
    {
    	long nItemIndex = 0;
    	CAksWorkSheet spWorkSheet = GetItem(strItemName);
    	if(spWorkSheet)
    		nItemIndex = spWorkSheet->GetIndex();
    	return nItemIndex;
    }
     
    long CAksWorkSheets::GetWorkSheetCount()
    {
    	long nCount = ((baseType)this)->GetCount();
    	return nCount;
    }
     
    POSITION CAksWorkSheets::GetFirstWorkSheetPosition()
    {
    	long nCount = ((baseType)this)->GetCount();
    	if(nCount == 0)
    		return NULL;
     
    	m_Pos = 1;
    	return (POSITION) &m_Pos;
    }
     
    IDispatchPtr CAksWorkSheets::GetNextWorkSheet(POSITION& pos)
    {
    	if( !pos )
    		return NULL;
     
    	long* pnIndex = (long*) pos;
    	ATLASSERT(pnIndex);
     
    	if( !pnIndex || *pnIndex < 1 )
    		return NULL;
     
    	CAksWorkSheet spWorkSheet;
     
    	long nCount = ((baseType)this)->GetCount();
    	if( *pnIndex <= nCount )
    	{
    		spWorkSheet= ((baseType)this)->GetItem(*pnIndex);
    		ATLASSERT(spWorkSheet);
    		(*pnIndex)++;
    	}
     
    	if(*pnIndex > nCount)
    		pos = NULL;
     
    	return spWorkSheet;
    }

  6. #26
    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
    L'implémentation de la CAksWorkSheet dans le fichier AksWorkSheet.cpp
    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
     
    #include "stdafx.h"
    #include "Aks.Excel.h"
    #include "AksWorkSheet.h"
     
     
    using namespace AKS::Automation::AksExcel;
     
    CString CAksWorkSheet::GetName(void)
    {
    	CString strName =((baseType)this)->GetName();
    	return strName;
    }
     
    void CAksWorkSheet::PutName(CString strName)
    {
    	if(strName.GetLength() > 31)
    	{
    		strName = strName.Left(28);
    		strName.Append(_T("..."));
    	}
    	((baseType)this)->PutName(strName.GetString());
    }
     
    Excel::RangePtr CAksWorkSheet::GetRange(const CString strAddr1, const CString strAddr2)
    {
    	if(strAddr1.IsEmpty() || strAddr2.IsEmpty())
    		return NULL;
     
    	return ((baseType)this)->GetRange(strAddr1.GetString(), strAddr2.GetString());
    }
     
    Excel::RangePtr CAksWorkSheet::GetRange(const CString strAddr)
    {
    	return GetRange(strAddr, strAddr);
    }
     
    Excel::RangePtr CAksWorkSheet::GetRange(CAksRange spTopLeft, CAksRange spBottomRight)
    {
    	if(spTopLeft == NULL || spBottomRight == NULL)
    		return NULL;
     
    	CString strTopLefAddr = spTopLeft.GetTopLeft().GetLocalAddress();
    	CString strBottomRight = spBottomRight.GetTopLeft().GetLocalAddress();
    	return GetRange(strTopLefAddr, strBottomRight);
    }
     
    Excel::RangePtr CAksWorkSheet::GetRange(CAksRange spTopLeft, long nRows, long nCols)
    {
    	if(spTopLeft == NULL || nRows <= 0 || nCols <= 0)
    		return NULL;
     
    	CAksRange spBottomRight = spTopLeft.GetTopLeft()->GetOffset(nRows-1, nCols-1);
    	return GetRange(spTopLeft, spBottomRight);
    }
     
    Excel::RangePtr CAksWorkSheet::GetRange(const CString strAddr, long nRows, long nCols)
    {
    	if(strAddr.IsEmpty() || nRows <= 0 || nCols <= 0)
    		return NULL;
     
    	CAksRange spTopLeft = GetRange(strAddr);
    	return GetRange(spTopLeft, nRows, nCols);
    }
     
    Excel::RangePtr CAksWorkSheet::GetRange(LPCTSTR szAddr, long nRows, long nCols)
    {
    	return GetRange(CString(szAddr), nRows, nCols);
    }
     
    Excel::RangePtr CAksWorkSheet::GetRange(long nRowPos, long nColPos, long nRows, long nCols)
    {
    	if(nRowPos < 1 || nColPos < 1 || nRows < 1 || nCols < 1)
    		return NULL;
     
    	Excel::RangePtr spOrigine = GetRange(_T("A1"));
    	CAksRange spTopLeft = spOrigine->GetOffset(nRowPos-1, nColPos-1);
    	return GetRange(spTopLeft, nRows, nCols);
    }
     
    Excel::RangePtr CAksWorkSheet::GetLimitRowRangeAt(long nRowPos, long nColPos)
    {
    	CAksRange spTopLeft = GetRange(nRowPos, nColPos, 1, 1);
    	if(spTopLeft == NULL)
    		return NULL;
     
    	return GetLimitRowRangeAt(spTopLeft);
    }
     
    Excel::RangePtr CAksWorkSheet::GetLimitRowRangeAt(CAksRange spTopLeft)
    {
    	if(spTopLeft == NULL)
    		return NULL;
     
    	CString strTopLeftAddr = spTopLeft.GetTopLeft().GetLocalAddress();
    	return GetLimitRowRangeAt(strTopLeftAddr);
    }
     
    // Renvoie une rangée unicolonne de taille maximale à partir de l'adresse spécifiée
    Excel::RangePtr CAksWorkSheet::GetLimitRowRangeAt(const CString strAddr)
    {
    	CAksRange spTop = GetRange(strAddr);
    	if(spTop == NULL)
    		return NULL;
     
    	CString strNoEmpty = spTop.GetValue();
    	if(strNoEmpty.IsEmpty())
    		return NULL;
     
    	CAksRange spBottom = spTop;
    	do
    	{	
    		spBottom = spBottom->GetOffset(1, 0);
    		strNoEmpty = spBottom.GetValue();
    	}
    	while(strNoEmpty.IsEmpty() == false);
     
    	spBottom = spBottom->GetOffset(-1, 0);
    	return GetRange(spTop, spBottom);
    }
     
    Excel::RangePtr CAksWorkSheet::GetLimitColRangeAt(long nRowPos, long nColPos)
    {
    	CAksRange spTopLeft = GetRange(nRowPos, nColPos, 1, 1);
    	if(spTopLeft == NULL)
    		return NULL;
     
    	return GetLimitColRangeAt(spTopLeft);
    }
     
    Excel::RangePtr CAksWorkSheet::GetLimitColRangeAt(CAksRange spTopLeft)
    {
    	if(spTopLeft == NULL)
    		return NULL;
     
    	CString strTopLeftAddr = spTopLeft.GetTopLeft().GetLocalAddress();
    	return GetLimitColRangeAt(strTopLeftAddr);
    }
     
    // Renvoie une rangée uniligne de taille maximale à partir de l'adresse spécifiée
    Excel::RangePtr CAksWorkSheet::GetLimitColRangeAt(const CString strAddr)
    {
    	CAksRange spLeft = GetRange(strAddr);
    	if(spLeft == NULL)
    		return NULL;
     
    	CString strNoEmpty = spLeft.GetValue();
    	if(strNoEmpty.IsEmpty())
    		return NULL;
     
    	CAksRange spRight = spLeft;
    	do
    	{	
    		spRight = spRight->GetOffset(0, 1);
    		strNoEmpty = spRight.GetValue();
    	}
    	while(strNoEmpty.IsEmpty() == false);
     
    	spRight = spRight->GetOffset(0, -1);
    	return GetRange(spLeft, spRight);
    }
     
    Excel::RangePtr CAksWorkSheet::GetLimitRangeAt(long nRowPos, long nColPos)
    {
    	CAksRange spTopLeft = GetRange(nRowPos, nColPos, 1, 1);
    	if(spTopLeft == NULL)
    		return NULL;
     
    	return GetLimitRangeAt(spTopLeft);
    }
     
    Excel::RangePtr CAksWorkSheet::GetLimitRangeAt(CAksRange spTopLeft)
    {
    	if(spTopLeft == NULL)
    		return NULL;
     
    	CString strTopLeftAddr = spTopLeft.GetTopLeft().GetLocalAddress();
    	return GetLimitRangeAt(strTopLeftAddr);
    }
     
    // Renvoie une rangée de taille maximale à partir de l'adresse spécifiée
    Excel::RangePtr CAksWorkSheet::GetLimitRangeAt(const CString strAddr)
    {
    	CAksRange spTopLeft = GetRange(strAddr);
    	if(spTopLeft == NULL)
    		return NULL;
     
    	CString strNoEmpty = spTopLeft.GetValue();
    	if(strNoEmpty.IsEmpty())
    		return NULL;
     
    	CAksRange spRows = GetLimitRowRangeAt(strAddr);
    	ATLASSERT(spRows);
    	CAksRange spCols = GetLimitColRangeAt(strAddr);
    	ATLASSERT(spCols);
     
    	long nRowCount = spRows.GetRowCount();
    	long nColCount = spCols.GetColCount();
     
    	return GetRange(spTopLeft, nRowCount, nColCount);
    }
     
    // Renvoie une rangée à nombre de lignes maximales à partir de l'adresse spécifiée
    Excel::RangePtr CAksWorkSheet::GetLimitRowRangeAt(CAksRange spTopLeft, long nColSize)
    {
    	if(spTopLeft == NULL || nColSize < 1)
    		return NULL;
    	CAksRange spLimitRange = GetLimitRowRangeAt(spTopLeft);
    	if(spLimitRange == NULL)
    		return NULL;
    	long nRows = spLimitRange.GetRowCount();
    	return spLimitRange->GetResize(nRows, nColSize);
    }
     
    Excel::RangePtr CAksWorkSheet::GetLimitRowRangeAt(const CString strAddr, long nColSize)
    {
    	CAksRange spLimitRange = GetRange(strAddr);
    	return GetLimitRowRangeAt(spLimitRange, nColSize);
    }
     
    // Renvoie une rangée à nombre de colonnes maximales à partir de l'adresse spécifiée
    Excel::RangePtr CAksWorkSheet::GetLimitColRangeAt(CAksRange spTopLeft, long nRowSize)
    {
    	if(spTopLeft == NULL || nRowSize < 1)
    		return NULL;
    	CAksRange spLimitRange = GetLimitColRangeAt(spTopLeft);
    	if(spLimitRange == NULL)
    		return NULL;
    	long nCols = spLimitRange.GetColCount();
    	return spLimitRange->GetResize(nRowSize, nCols);
    }
     
    Excel::RangePtr CAksWorkSheet::GetLimitColRangeAt(const CString strAddr, long nRowSize)
    {
    	CAksRange spLimitRange = GetRange(strAddr);
    	return GetLimitColRangeAt(spLimitRange, nRowSize);
    }
     
    long CAksWorkSheet::GetTotalRowCount()
    {
    	return ((baseType)this)->GetRows()->GetCount();
    }
     
    long CAksWorkSheet::GetTotalColCount()
    {
    	return ((baseType)this)->GetColumns()->GetCount();
    }
     
    CAksRange CAksWorkSheet::LoadSheetHeader(const CString strAddr, const CHeaderCtrl* pHeaderCtrl)
    {
    	CAksRange spTopLeft = GetRange(strAddr);
    	if( !spTopLeft )
    		return NULL;
     
    	return LoadSheetHeader(spTopLeft, pHeaderCtrl);
    }
     
    CAksRange CAksWorkSheet::LoadSheetHeader(long nRowPos, long nColPos, const CHeaderCtrl* pHeaderCtrl)
    {
    	CAksRange spTopLeft = GetRange(nRowPos, nColPos, 1, 1);
    	if( !spTopLeft )
    		return NULL;
     
    	return LoadSheetHeader(spTopLeft, pHeaderCtrl);
    }
     
    CAksRange CAksWorkSheet::LoadSheetHeader(CAksRange spTopLeft, const CHeaderCtrl* pHeaderCtrl)
    {
    	if( !spTopLeft || !pHeaderCtrl || !::IsWindow(pHeaderCtrl->GetSafeHwnd()) )
    		return NULL;
     
    	int nCount = pHeaderCtrl->GetItemCount();
    	if(nCount == 0)
    		return NULL;
     
    	CAksRange spHeader = GetRange(spTopLeft, 1, nCount);
    	if( !spHeader )
    		return NULL;
     
    	LPINT OrderArray = new int[nCount];
    	ATLASSERT(OrderArray);
    	pHeaderCtrl->GetOrderArray(OrderArray, nCount);
     
    	int iItem = 0;
    	for(int nOrderCol = 0; nOrderCol < nCount; nOrderCol++)
    	{
    		int nCol = OrderArray[nOrderCol];
    		CString strColumnText;
     
    		HDITEM hdItem;
    		hdItem.mask = HDI_TEXT | HDI_FORMAT | HDI_WIDTH;
    		hdItem.pszText = strColumnText.GetBuffer(50);
    		hdItem.cchTextMax = 50;
    		pHeaderCtrl->GetItem(nCol, &hdItem);
    		strColumnText.ReleaseBuffer();
     
    		if(hdItem.cxy <= 0)
    			continue; // this item is hidden
     
    		iItem++;
     
    		if( (hdItem.fmt & HDF_CENTER) == HDF_CENTER )
    			spHeader.GetCellAt(1, iItem).SetHorizAlign(Excel::xlHAlignCenter);
    		else if( (hdItem.fmt & HDF_RIGHT) == HDF_RIGHT )
    			spHeader.GetCellAt(1, iItem).SetHorizAlign(Excel::xlHAlignRight);
    		else
    			spHeader.GetCellAt(1, iItem).SetHorizAlign(Excel::xlHAlignLeft);
     
    		spHeader.PutItem(1, iItem, strColumnText);
    	}
     
    	delete[] OrderArray;
     
    	int nVisibleItems = iItem;
    	if(nVisibleItems > 0)
    		return spHeader.GetSubRangeAt(1, 1, 1, nVisibleItems);
    	return NULL;
    }
     
     
    CAksRange CAksWorkSheet::LoadSheet(const CString strAddr, const CListCtrl& rListCtrl, bool bIncludeHeader /*= true*/)
    {
    	CAksRange spTopLeft = GetRange(strAddr);
    	if( !spTopLeft )
    		return NULL;
     
    	return LoadSheet(spTopLeft, rListCtrl, bIncludeHeader);
    }
     
    CAksRange CAksWorkSheet::LoadSheet(long nRowPos, long nColPos, const CListCtrl& rListCtrl, bool bIncludeHeader /*= true*/)
    {
    	CAksRange spTopLeft = GetRange(nRowPos, nColPos, 1, 1);
    	if( !spTopLeft )
    		return NULL;
     
    	return LoadSheet(spTopLeft, rListCtrl, bIncludeHeader);
    }
     
    CAksRange CAksWorkSheet::LoadSheet(CAksRange spTopLeft, const CListCtrl& rListCtrl, bool bIncludeHeader /*= true*/)
    {
    	if( !spTopLeft || !::IsWindow(rListCtrl.GetSafeHwnd()) )
    		return NULL;
     
    	CHeaderCtrl* pHeaderCtrl = rListCtrl.GetHeaderCtrl();
    	int nColCount = pHeaderCtrl->GetItemCount();
    	if(nColCount == 0)
    		return NULL;
     
    	int nCount = rListCtrl.GetItemCount();
    	CAksRange spList;
    	if( bIncludeHeader )
    	{
    		CAksRange spHeader = LoadSheetHeader(spTopLeft, pHeaderCtrl);
    		if( !spHeader )
    			return NULL;
     
    		if(nCount == 0)
    			return spHeader;  // no item, just return the header
     
    		spList = GetRange(spHeader, nCount+1, spHeader.GetColCount());
    	}
    	else
    		spList = GetRange(spTopLeft, nCount, nColCount);
     
    	if( !spList )
    		return NULL;
     
    	LPINT OrderArray = new int[nColCount];
    	ATLASSERT(OrderArray);
    	pHeaderCtrl->GetOrderArray(OrderArray, nColCount);
     
    	int nMaxCols = 0;
    	for(int iItem = 0; iItem < nCount; iItem++)
    	{
    		int nColAt = 0;
    		for(int nOrderCol = 0; nOrderCol < nColCount; nOrderCol++)
    		{
    			int nCol = OrderArray[nOrderCol];
     
    			HDITEM hdItem;
    			hdItem.mask = HDI_LPARAM | HDI_WIDTH | HDI_FORMAT;
    			pHeaderCtrl->GetItem(nCol, &hdItem);
     
    			if(hdItem.cxy <= 0)
    				continue; // this column is hidden
     
    			Excel::XlHAlign nXlAlign = Excel::xlHAlignGeneral;
     
    			if( (hdItem.fmt & HDF_CENTER) == HDF_CENTER )
    				nXlAlign = Excel::xlHAlignCenter;
    			else if( (hdItem.fmt & HDF_RIGHT) == HDF_RIGHT )
    				nXlAlign = Excel::xlHAlignRight;
    			else
    				nXlAlign = Excel::xlHAlignLeft;
     
    			AKS::CAksVariant Value;
    			CString strValue = rListCtrl.GetItemText(iItem, nCol);
     
    			switch(hdItem.lParam)
    			{
    			case VT_R8:
    				{
    					char* pEnd = NULL;
    					strValue.Remove(' ');
    					strValue.Replace(',', '.');
    					double dValue = ::strtod(CStringA(strValue).GetString(), &pEnd);
    					Value = dValue;
    				}
    				break;
     
    			case VT_DATE:
    				{
    					COleDateTime dtDateTime;
    					dtDateTime.ParseDateTime(strValue);
    					Value = strValue; // get it as a string date;
    				}
    				break;
     
    			default:
    				Value = strValue;
    			}
     
    			spList.PutItem(iItem+2, ++nColAt, Value);
    			spList.GetCellAt(iItem+2, nColAt).SetHorizAlign(nXlAlign);
    		}
    		nMaxCols = nColAt;
    	}
     
    	ATLASSERT(nMaxCols > 0);
    	delete[] OrderArray;
    	return bIncludeHeader? spList: spList.GetSubRangeAt(1, 1, spList.GetRowCount(), nMaxCols);  // done!!!
    }
     
    CAksRange CAksWorkSheet::LoadHeader(long nRowPos, long nColPos, long nRows, long nCols, CListCtrl& rListCtrl)
    {
    	CAksRange spHeader = GetRange(nRowPos, nColPos, nRows, nCols);
    	if(spHeader == NULL)
    		return NULL;
     
    	return LoadHeader(spHeader, rListCtrl);
    }
     
    CAksRange CAksWorkSheet::LoadHeader(const CString strAddr, long nRows, long nCols, CListCtrl& rListCtrl)
    {
    	CAksRange spHeader = GetRange(strAddr, nRows, nCols);
    	if(spHeader == NULL)
    		return NULL;
     
    	return LoadHeader(spHeader, rListCtrl);
    }

  7. #27
    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
    et la suite de CAksWorkSheet

    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
     
    CAksRange CAksWorkSheet::LoadHeader(CAksRange spHeader, CListCtrl& rListCtrl, bool bAutoColumnText /*= false*/)
    {
    	if( !spHeader /*|| !pHeaderCtrl || !::IsWindow(pHeaderCtrl->GetSafeHwnd()) */)
    		return NULL;
     
    	CHeaderCtrl* pHeaderCtrl = rListCtrl.GetHeaderCtrl();
    	while(rListCtrl.DeleteColumn(0));
    	while(pHeaderCtrl && pHeaderCtrl->DeleteItem(0));
    	int nCount = pHeaderCtrl? pHeaderCtrl->GetItemCount(): 0;
    	ATLASSERT(nCount == 0);
     
    	//while( pHeaderCtrl->DeleteItem(0) );
    	//int nCount = pHeaderCtrl->GetItemCount();
    	//ATLASSERT(nCount == 0);
     
    	LVCOLUMN lvColumn;	
    	lvColumn.mask = LVCF_FMT | LVCF_TEXT | LVCF_WIDTH;
    	lvColumn.cx = 150;
     
    	HDITEM hdItem;
    	hdItem.mask = HDI_FORMAT | HDI_WIDTH | HDI_TEXT;
     
    	int nItems = spHeader.GetColCount();
     
    	for(int nItem = 1; nItem <= nItems; nItem++)
    	{
    		hdItem.fmt = HDF_STRING;
     
    #if _WIN32_WINNT >= 0x0600  // Vista
    		hdItem.fmt |= HDF_SPLITBUTTON; 
    #endif
     
    		lvColumn.cx = 10 * spHeader.GetColumnWidth(1, nItem);
    		hdItem.cxy = 10 * spHeader.GetColumnWidth(1, nItem);
     
    		CString strItemText;
    		if(bAutoColumnText)
    			strItemText.Format(_T("Colonne %d"), nItem);
    		else
    			strItemText = spHeader.GetItem(1, nItem);
     
    		lvColumn.cchTextMax = strItemText.GetLength();
    		lvColumn.pszText = strItemText.GetBuffer(lvColumn.cchTextMax);
     
    		hdItem.cchTextMax = strItemText.GetLength();
    		hdItem.pszText = strItemText.GetBuffer(hdItem.cchTextMax);
     
    		Excel::XlHAlign Align = spHeader.GetCellAt(1, nItem).GetHorizAlign();
     
    		if( (Align & Excel::xlHAlignCenter) == Excel::xlHAlignCenter )
    		{
    			hdItem.fmt |= HDF_CENTER;
    			lvColumn.fmt = LVCFMT_CENTER;
    		}
    		else if( (Align & Excel::xlHAlignRight) == Excel::xlHAlignRight )
    		{
    			hdItem.fmt |= HDF_RIGHT;
    			lvColumn.fmt = LVCFMT_RIGHT;
    		}
    		else
    		{
    			hdItem.fmt |= HDF_LEFT;
    			lvColumn.fmt = LVCFMT_LEFT;
    		}
     
    		lvColumn.iSubItem = nItem-1;
    		int nIndex = rListCtrl.InsertColumn(nItem-1, &lvColumn);
     
    		if(pHeaderCtrl)
    			pHeaderCtrl->SetItem(nItem-1, &hdItem);
     
    		//pHeaderCtrl->InsertItem(nItem-1, &hdItem);
    		strItemText.ReleaseBuffer();
    	}
     
    	//nCount = pHeaderCtrl->GetItemCount();
    	//ATLASSERT(nCount == nItems);
    	return spHeader.GetSubRangeAt(1, 1, 1, nItems);
    }
     
    CAksRange CAksWorkSheet::LoadList(long nRowPos, long nColPos, long nRows, long nCols, CListCtrl& rListCtrl, bool bIncludeHeader /*= true*/)
    {
    	CAksRange spList = GetRange(nRowPos, nColPos, nRows, nCols);
    	if(spList == NULL)
    		return NULL;
     
    	return LoadList(spList, rListCtrl, bIncludeHeader);
    }
     
    CAksRange CAksWorkSheet::LoadList(const CString strAddr, long nRows, long nCols, CListCtrl& rListCtrl, bool bIncludeHeader /*= true*/)
    {
    	CAksRange spList = GetRange(strAddr, nRows, nCols);
    	if(spList == NULL)
    		return NULL;
     
    	return LoadList(spList, rListCtrl, bIncludeHeader);
    }
     
    CAksRange CAksWorkSheet::LoadList(CAksRange spTopLeft, CAksRange spBottomRight, CListCtrl& rListCtrl, bool bIncludeHeader /*= true*/)
    {
    	CAksRange spList = GetRange(spTopLeft, spBottomRight);
    	if(spList == NULL)
    		return NULL;
     
    	return LoadList(spList, rListCtrl, bIncludeHeader);
    }
     
    CAksRange CAksWorkSheet::LoadList(CAksRange spList, CListCtrl& rListCtrl, bool bIncludeHeader /*= true*/)
    {
    	if( !spList || !::IsWindow(rListCtrl.GetSafeHwnd()) )
    		return NULL;
     
    	if( bIncludeHeader )
    	{
    		CAksRange spHeader = LoadHeader(spList, rListCtrl);
    		if( !spHeader )
    			return NULL;
     
    		spList.RemoveTopRow();
    	}
    	else
    	{
    		CHeaderCtrl* pHeaderCtrl = rListCtrl.GetHeaderCtrl();
    		if( !pHeaderCtrl || !::IsWindow(pHeaderCtrl->GetSafeHwnd()) ) 
    			return NULL;
     
    		int nCols = spList.GetColCount();
    		int nCount = pHeaderCtrl->GetItemCount();
    		if(nCount == 0 || nCols != nCount)
    		{
    			if( !LoadHeader(spList, rListCtrl, true) )
    				return NULL;
    		}
    	}
     
    	if( !spList )
    		return NULL;
     
    	int nRows = spList.GetRowCount();
    	int nCols = spList.GetColCount();
     
    	for(int nRow = 1; nRow <= nRows; nRow++)
    	{
    		CString strItemData = spList.GetItem(nRow, 1);
     
    		LVITEM lvItem;
    		lvItem.mask = LVIF_TEXT | LVIF_IMAGE; 
    		lvItem.iItem = nRow-1;
    		lvItem.iSubItem = 0;
    		lvItem.pszText = strItemData.GetBuffer(strItemData.GetLength()+1);  
    		lvItem.cchTextMax = lstrlen(lvItem.pszText);
    		lvItem.iImage = 0;
     
    		rListCtrl.InsertItem(&lvItem);
     
    		for(int nCol = 2; nCol <= nCols; nCol++)
    		{
    			strItemData = spList.GetItem(nRow, nCol);
    			rListCtrl.SetItemText(nRow-1, nCol-1, strItemData);
    		}
    	}
     
    	if( bIncludeHeader )
    		spList.AddTopRow();
    	return spList;
    }
     
    CAksWorkSheet CAksWorkSheet::GetPreviousSheet()
    {
    	return ((baseType)this)->GetPrevious();
    }
     
    CAksWorkSheet CAksWorkSheet::GetNextSheet()
    {
    	return ((baseType)this)->GetNext();
    }
     
    long CAksWorkSheet::GetSheetIndex()
    {
    	return ((baseType)this)->GetIndex();
    }
     
    HRESULT CAksWorkSheet::MoveSheet(CAksWorkSheet spBefore, CAksWorkSheet spAfter)
    {
    	if( !spBefore && spAfter )
    		return ((baseType)this)->Move(vtMissing, spAfter.GetSheetIndex());
    	else if( spBefore && !spAfter )
    		return ((baseType)this)->Move(spBefore.GetSheetIndex(), vtMissing);
    	else
    		return E_FAIL;
    }
     
    HRESULT CAksWorkSheet::SaveAs(
    		CString strXlFile, 
    		CString strPassword, 
    		CString strWriteResPassword,
    		bool bReadOnly)
    {
    	if(strXlFile.IsEmpty())
    		return E_POINTER;
     
    	HRESULT hr = ((baseType)this)->_SaveAs(
    			strXlFile.GetString(),									// Filename
    			Excel::xlWorkbookNormal,								// FileFormat
    			strPassword.GetString(),								// Password
    			strWriteResPassword.GetString(),						// WriteResPassword
    			bReadOnly,												// ReadOnlyRecommended
    			false);													// CreateBackup
     
    	return hr;
    }
     
    void CAksWorkSheet::CopyRange(CAksRange spSource, CAksRange spDestination)
    {
    	if( !spSource || !spDestination )
    		return;
     
    	spDestination.CopyRange(spSource);
    }
     
    CAksRange CAksWorkSheet::ResearchV(const CString strVal, CAksRange spCol, bool bAddBottom /*= false*/)
    {
    	if( !spCol || spCol.GetColCount() != 1)
    		return NULL;
     
    	long nRowFound = -1;
    	long nColFound = -1;
    	spCol.FindData(strVal, nRowFound, nColFound);
     
    	if(nRowFound != -1)
    		return spCol.GetCellAt(nRowFound, 1);
     
    	if(bAddBottom)
    	{
    		spCol.AddBottomRow().PutItem(1, 1, strVal);
    		return spCol.GetBottomLeft();
    	}
     
    	return NULL;
    }
     
    CAksRange CAksWorkSheet::ResearchV(const CString strVal, const CString strAddr1, const CString strAddr2, bool bAddBottom /*= false*/)
    {
    	return ResearchV(strVal, GetRange(strAddr1, strAddr2), bAddBottom);
    }
     
    CAksRange CAksWorkSheet::ResearchV(const CString strVal, const CString strAddr, long nRowSize, bool bAddBottom /*= false*/)
    {
    	return ResearchV(strVal, GetRange(strAddr, nRowSize, 1), bAddBottom);
    }
     
    CAksRange CAksWorkSheet::ResearchV(const CString strVal, const CString strAddr, bool bAddBottom /*= false*/)
    {
    	CAksRange spCol = GetLimitRowRangeAt(strAddr);
    	if( !spCol && bAddBottom )
    	{
    		spCol = GetRange(strAddr);
    		spCol.PutItem(1, 1, strVal);
    		return spCol;
    	}
    	return ResearchV(strVal, spCol, bAddBottom);
    }
     
    CAksRange CAksWorkSheet::ResearchH(const CString strVal, CAksRange spRow, bool bAddRight /*= false*/)
    {
    	if( !spRow || spRow.GetRowCount() != 1)
    		return NULL;
     
    	long nRowFound = -1;
    	long nColFound = -1;
    	spRow.FindData(strVal, nRowFound, nColFound);
     
    	if(nColFound != -1)
    		return spRow.GetCellAt(1, nColFound);
     
    	if(bAddRight)
    	{
    		spRow.AddRightColumn().PutItem(1, 1, strVal);
    		return spRow.GetTopRight();
    	}
     
    	return NULL;
    }
     
    CAksRange CAksWorkSheet::ResearchH(const CString strVal, const CString strAddr1, const CString strAddr2, bool bAddRight /*= false*/)
    {
    	return ResearchH(strVal, GetRange(strAddr1, strAddr2), bAddRight);
    }
     
    CAksRange CAksWorkSheet::ResearchH(const CString strVal, const CString strAddr, long nColSize, bool bAddRight /*= false*/)
    {
    	return ResearchH(strVal, GetRange(strAddr, 1, nColSize), bAddRight);
    }
     
    CAksRange CAksWorkSheet::ResearchH(const CString strVal, const CString strAddr, bool bAddRight /*= false*/)
    {
    	CAksRange spRow = GetLimitColRangeAt(strAddr);
    	if( !spRow && bAddRight )
    	{
    		spRow = GetRange(strAddr);
    		spRow.PutItem(1, 1, strVal);
    		return spRow;
    	}
    	return ResearchH(strVal, spRow, bAddRight);
    }
     
    CAksRange CAksWorkSheet::MultiResearchV(
    					AKS::Utility::CAksVariantArray& arValues,
    					AKS::Utility::CAksVariantArray& arOffsetCols,
    					CAksRange spRefCol,
    					bool bAddBottom /*= false*/,
    					bool bIncludeEmpty /*= true*/)
    {
    	if( arValues.IsEmpty() || arOffsetCols.IsEmpty() || 
    		(arValues.GetCount() != arOffsetCols.GetCount()) || 
    		!spRefCol )
    		return NULL;
     
    	spRefCol = spRefCol.GetLeftColumn();
     
    	long nCount = arValues.GetCount();
    	long nRows = spRefCol.GetRowCount();
     
    	for(long nRow = 1; nRow <= nRows; nRow++)
    	{
    		bool bFound = true;
     
    		for(long nItem = 0; nItem < nCount; nItem++)
    		{
    			CAksVariant varValue = arValues.GetAt(nItem);
    			long nOffsetCol = arOffsetCols.GetAt(nItem);
     
    			CAksVariant varOffsetItem = spRefCol.GetOffsetItem(nRow, 1, 0, nOffsetCol);
     
    			if( bIncludeEmpty )
    			{
    				if( (varValue != varOffsetItem) )
    				{
    					bFound = false;
    					break;
    				}
    			}
    			else
    			{
    				if( !varOffsetItem.IsEmpty() && (varValue != varOffsetItem) )
    				{
    					bFound = false;
    					break;
    				}
    			}
    		}
     
    		if(bFound)
    			return spRefCol.GetCellAt(nRow, 1);
    	}
     
    	if(bAddBottom)
    	{
    		CAksRange spLastRow = spRefCol.AddBottomRow();
     
    		for(long nItem = 0; nItem < nCount; nItem++)
    		{
    			CAksVariant varValue = arValues.GetAt(nItem);
    			long nOffsetCol = arOffsetCols.GetAt(nItem);
     
    			spLastRow.PutOffsetItem(1, 1, 0, nOffsetCol, varValue);
    		}
     
    		return spLastRow;
    	}
     
    	return NULL;
    }
     
    CAksRange CAksWorkSheet::MultiResearchV(
    					AKS::Utility::CAksVariantArray& arValues,
    					AKS::Utility::CAksVariantArray& arOffsetCols,
    					const CString strAddr1, 
    					const CString strAddr2,
    					bool bAddBottom /*= false*/,
    					bool bIncludeEmpty /*= true*/)
    {
    	return MultiResearchV(arValues, arOffsetCols, GetRange(strAddr1, strAddr2), bAddBottom, bIncludeEmpty);
    }
     
    CAksRange CAksWorkSheet::MultiResearchV(
    					AKS::Utility::CAksVariantArray& arValues,
    					AKS::Utility::CAksVariantArray& arOffsetCols,
    					const CString strAddr, 
    					long nRowSize,
    					bool bAddBottom /*= false*/,
    					bool bIncludeEmpty /*= true*/)
    {
    	return MultiResearchV(arValues, arOffsetCols, GetRange(strAddr, nRowSize, 1), bAddBottom, bIncludeEmpty);
    }
     
    CAksRange CAksWorkSheet::MultiResearchV(
    					AKS::Utility::CAksVariantArray& arValues,
    					AKS::Utility::CAksVariantArray& arOffsetCols,
    					const CString strAddr,
    					bool bAddBottom /*= false*/,
    					bool bIncludeEmpty /*= true*/)
    {
    	CAksRange spRefCol = GetLimitRowRangeAt(strAddr);
    	if( !spRefCol && bAddBottom )
    	{
    		spRefCol = GetRange(strAddr);
    		long nCount = arValues.GetCount();
    		for(long nItem = 0; nItem < nCount; nItem++)
    		{
    			CAksVariant varValue = arValues.GetAt(nItem);
    			long nOffsetCol = arValues.GetAt(nItem);
     
    			spRefCol.PutOffsetItem(1, 1, 0, nOffsetCol, varValue);
    		}
     
    		return spRefCol;
    	}
    	return MultiResearchV(arValues, arOffsetCols, spRefCol, bAddBottom, bIncludeEmpty);
    }
     
    CAksRange CAksWorkSheet::MultiResearchH(
    					AKS::Utility::CAksVariantArray& arValues,
    					AKS::Utility::CAksVariantArray& arOffsetRows,
    					CAksRange spRefRow,
    					bool bAddRight /*= false*/,
    					bool bIncludeEmpty /*= true*/)
    {
    	if( arValues.IsEmpty() || arOffsetRows.IsEmpty() || 
    		(arValues.GetCount() != arOffsetRows.GetCount()) || 
    		!spRefRow )
    		return NULL;
     
    	spRefRow = spRefRow.GetTopRow();
     
    	long nCount = arValues.GetCount();
    	long nCols = spRefRow.GetColCount();
     
    	for(long nCol = 1; nCol <= nCols; nCol++)
    	{
    		bool bFound = true;
     
    		for(long nItem = 0; nItem < nCount; nItem++)
    		{
    			CAksVariant varValue = arValues.GetAt(nItem);
    			long nOffsetRow = arOffsetRows.GetAt(nItem);
     
    			CAksVariant varOffsetItem = spRefRow.GetOffsetItem(1, nCol, nOffsetRow, 0);
     
    			if( bIncludeEmpty )
    			{
    				if( (varValue != varOffsetItem) )
    				{
    					bFound = false;
    					break;
    				}
    			}
    			else
    			{
    				if( !varOffsetItem.IsEmpty() && (varValue != varOffsetItem) )
    				{
    					bFound = false;
    					break;
    				}
    			}
    		}
     
    		if(bFound)
    			return spRefRow.GetCellAt(1, nCol);
    	}
     
    	if(bAddRight)
    	{
    		CAksRange spLastCol = spRefRow.AddRightColumn();
     
    		for(long nItem = 0; nItem < nCount; nItem++)
    		{
    			CAksVariant varValue = arValues.GetAt(nItem);
    			long nOffsetRow = arOffsetRows.GetAt(nItem);
     
    			spLastCol.PutOffsetItem(1, 1, nOffsetRow, 0, varValue);
    		}
     
    		return spLastCol;
    	}
     
    	return NULL;
    }
     
    CAksRange CAksWorkSheet::MultiResearchH(
    					AKS::Utility::CAksVariantArray& arValues,
    					AKS::Utility::CAksVariantArray& arOffsetRows,
    					const CString strAddr1, 
    					const CString strAddr2,
    					bool bAddRight /*= false*/,
    					bool bIncludeEmpty /*= true*/)
    {
    	return MultiResearchH(arValues, arOffsetRows, GetRange(strAddr1, strAddr2), bAddRight, bIncludeEmpty);
    }
     
    CAksRange CAksWorkSheet::MultiResearchH(
    					AKS::Utility::CAksVariantArray& arValues,
    					AKS::Utility::CAksVariantArray& arOffsetRows,
    					const CString strAddr, 
    					long nColSize,
    					bool bAddRight /*= false*/,
    					bool bIncludeEmpty /*= true*/)
    {
    	return MultiResearchV(arValues, arOffsetRows, GetRange(strAddr, 1, nColSize), bAddRight, bIncludeEmpty);
    }
     
    CAksRange CAksWorkSheet::MultiResearchH(
    					AKS::Utility::CAksVariantArray& arValues,
    					AKS::Utility::CAksVariantArray& arOffsetRows,
    					const CString strAddr,
    					bool bAddRight /*= false*/,
    					bool bIncludeEmpty /*= true*/)
    {
    	CAksRange spRefRow = GetLimitColRangeAt(strAddr);
    	if( !spRefRow && bAddRight )
    	{
    		spRefRow = GetRange(strAddr);
    		long nCount = arValues.GetCount();
    		for(long nItem = 0; nItem < nCount; nItem++)
    		{
    			CAksVariant varValue = arValues.GetAt(nItem);
    			long nOffsetRow = arOffsetRows.GetAt(nItem);
     
    			spRefRow.PutOffsetItem(1, 1, nOffsetRow, 0, varValue);
    		}
     
    		return spRefRow;
    	}
    	return MultiResearchH(arValues, arOffsetRows, spRefRow, bAddRight, bIncludeEmpty);
    }

  8. #28
    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
    L'implémentation de la CAksRange dans le fichier AksRange.cpp

    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
     
    #include "stdafx.h"
    #include "Aks.Excel.h"
    #include "AksRange.h"
     
    using namespace AKS::Automation::AksExcel;
     
    long CAksRange::GetRowPosition()
    {
    	return ((baseType)this)->GetRow();
    }
     
    long CAksRange::GetColPosition()
    {
    	return ((baseType)this)->GetColumn();
    }
     
    long CAksRange::GetRowCount()
    {
    	return ((baseType)this)->GetRows()->GetCount();
    }
     
    long CAksRange::GetColCount()
    {
    	return ((baseType)this)->GetColumns()->GetCount();
    }
     
    void CAksRange::PutValue(AKS::CAksVariant value)
    {
    	((baseType)this)->PutValue2(value);
    }
     
    AKS::CAksVariant CAksRange::GetValue()
    {
    	return ((baseType)this)->GetValue2();
    }
     
    CAksRange CAksRange::GetCellAt(long nRow, long nCol)
    {
    	long nRowCount = GetRowCount();
    	long nColCount = GetColCount();
     
    	if(nRow < 1 || nRow > nRowCount)
    		return NULL;
    	else if(nCol < 1 || nCol > nColCount)
    		return NULL;
     
    	Excel::RangePtr spTopLeft = ((baseType)this)->GetResize(1, 1);
    	return spTopLeft->GetOffset(nRow-1, nCol-1);
    }
     
    CAksRange CAksRange::GetOffsetCellAt(long nRow, long nCol, long nOffsetRow, long nOffsetCol)
    {
    	CAksRange spCell = GetCellAt(nRow, nCol);
    	if( !spCell )
    		return NULL;
     
    	CAksWorkSheet spParent = ((baseType)this)->GetWorksheet();
    	ATLASSERT(spParent);
     
    	long nRowPos = spCell.GetRowPosition();
    	if(nOffsetRow < 0)
    	{
    		if( (nRowPos + nOffsetRow) < 1)
    			return NULL;
    	}
    	else
    	{
    		long nTotalRows = spParent.GetTotalRowCount();
    		if( (nRowPos + nOffsetRow) > nTotalRows)
    			return NULL;
    	}
     
    	long nColPos = spCell.GetColPosition();
    	if(nOffsetCol < 0)
    	{
    		if( (nColPos + nOffsetCol) < 1)
    			return NULL;
    	}
    	else
    	{
    		long nTotalCols = spParent.GetTotalColCount();
    		if( (nColPos + nOffsetCol) > nTotalCols)
    			return NULL;
    	}
     
    	CAksRange spOffset = spCell->GetOffset(nOffsetRow, nOffsetCol);
    	return spOffset;
    }
     
    AKS::CAksVariant CAksRange::GetItem(long nRow, long nCol)
    {
    	long nRowCount = GetRowCount();
    	long nColCount = GetColCount();
     
    	ATLASSERT(nRow >= 1 && nRow <= nRowCount);
    	ATLASSERT(nCol >= 1 && nCol <= nColCount);
     
    	return ((baseType)this)->GetItem(nRow, nCol);
    }
     
    void CAksRange::PutItem(long nRow, long nCol, AKS::CAksVariant value)
    {
    	long nRowCount = GetRowCount();
    	long nColCount = GetColCount();
     
    	ATLASSERT(nRow >= 1 && nRow <= nRowCount);
    	ATLASSERT(nCol >= 1 && nCol <= nColCount);
     
    	((baseType)this)->PutItem(nRow, nCol, value);
    }
     
    AKS::CAksVariant CAksRange::GetOffsetItem(long nRow, long nCol, long nOffsetRow, long nOffsetCol)
    {
    	CAksRange spCell = GetOffsetCellAt(nRow, nCol, nOffsetRow, nOffsetCol);
    	if( !spCell)
    		return AKS::CAksVariant();
     
    	return spCell.GetValue();
    }
     
    void CAksRange::PutOffsetItem(long nRow, long nCol, long nOffsetRow, long nOffsetCol, AKS::CAksVariant value)
    {
    	CAksRange spCell = GetOffsetCellAt(nRow, nCol, nOffsetRow, nOffsetCol);
    	if(spCell)
    		spCell.PutValue(value);
    }
     
    CString CAksRange::GetLocalAddress()
    {
    	_bstr_t bstrAddr = ((baseType)this)->GetAddressLocal(0, 0, Excel::xlA1);
    	return CString(bstrAddr.GetBSTR());
    }
     
    CString CAksRange::GetLocalAddress(long nRow, long nCol)
    {
    	CAksRange spCell = GetCellAt(nRow, nCol);
    	if(spCell)
    		return spCell.GetLocalAddress();
    	return CString();
    }
     
    CString CAksRange::GetOffsetLocalAddress(long nRow, long nCol, long nOffsetRow, long nOffsetCol)
    {
    	CAksRange spCell = GetOffsetCellAt(nRow, nCol, nOffsetRow, nOffsetCol);
    	if(spCell)
    		return spCell.GetLocalAddress();
    	return CString();
    }
     
    CAksRange CAksRange::GetTopLeft()
    {
    	return ((baseType)this)->GetResize(1, 1);
    }
     
    CAksRange CAksRange::GetTopRight()
    {
    	long nColCount = GetColCount();
    	return GetCellAt(1, nColCount);
    }
     
    CAksRange CAksRange::GetBottomLeft()
    {
    	long nRowCount = GetRowCount();
    	return GetCellAt(nRowCount, 1);
    }
     
    CAksRange CAksRange::GetBottomRight()
    {
    	long nColCount = GetColCount();
    	long nRowCount = GetRowCount();
    	return GetCellAt(nRowCount, nColCount);
    }
     
    CAksRange CAksRange::GetRowAt(long nRow)
    {
    	long nColCount = GetColCount();
    	long nRowCount = GetRowCount();
    	if(nRow < 1 || nRow > nRowCount)
    		return NULL;
     
    	CAksRange spRow = GetCellAt(nRow, 1);
    	return spRow->GetResize(1, nColCount);
    }
     
    CAksRange CAksRange::GetColAt(long nCol)
    {
    	long nColCount = GetColCount();
    	long nRowCount = GetRowCount();
    	if(nCol < 1 || nCol > nColCount)
    		return NULL;
     
    	CAksRange spCol = GetCellAt(1, nCol);
    	return spCol->GetResize(nRowCount, 1);
    }
     
    CAksRange CAksRange::GetOffsetRowAt(long nOffsetRow)
    {
    	long nRowPos = GetRowPosition();
    	if(nOffsetRow < 0)
    	{
    		if( (nRowPos + nOffsetRow) < 1)
    			return NULL;
    	}
    	else
    	{
    		CAksWorkSheet spParent = ((baseType)this)->GetWorksheet();
    		ATLASSERT(spParent);
    		long nTotalRows = spParent.GetTotalRowCount();
    		if( (nRowPos + nOffsetRow) > nTotalRows)
    			return NULL;
    	}
    	CAksRange spTopRow = GetTopRow();
    	return spTopRow->GetOffset(nOffsetRow, 0);
    }
     
    CAksRange CAksRange::GetOffsetColAt(long nOffsetCol)
    {
    	long nColPos = GetColPosition();
    	if(nOffsetCol < 0)
    	{
    		if( (nColPos + nOffsetCol) < 1)
    			return NULL;
    	}
    	else
    	{
    		CAksWorkSheet spParent = ((baseType)this)->GetWorksheet();
    		ATLASSERT(spParent);
    		long nTotalCols = spParent.GetTotalColCount();
    		if( (nColPos + nOffsetCol) > nTotalCols)
    			return NULL;
    	}
    	CAksRange spLeftCol = GetLeftColumn();
    	return spLeftCol->GetOffset(0, nOffsetCol);
    }
     
    CAksRange CAksRange::GetSubRangeAt(long nRowPos, long nColPos, long nRows, long nCols)
    {
    	long nColCount = GetColCount();
    	long nRowCount = GetRowCount();
     
    	if(nRows < 1 || nRows > (nRowCount - nRowPos + 1))
    		return NULL;
    	else if(nCols < 1 || nCols > (nColCount - nColPos + 1))
    		return NULL;
     
    	Excel::RangePtr spTopLeft = GetCellAt(nRowPos, nColPos);
    	if(spTopLeft == NULL)
    		return NULL;
    	return spTopLeft->GetResize(nRows, nCols);
    }
     
    CAksRange CAksRange::AddTopRow()
    {
    	long nRowPos = GetRowPosition();
    	if(nRowPos <= 1)
    		return NULL;
    	long nRows = GetRowCount();
    	long nCols = GetColCount();
    	CAksRange spThis = ((baseType)this)->GetOffset(-1, 0);
    	*this = spThis->GetResize(nRows+1, nCols);
    	return GetRowAt(1);
    }
     
    CAksRange CAksRange::AddBottomRow()
    {
    	CAksWorkSheet spParent = ((baseType)this)->GetWorksheet();
    	ATLASSERT(spParent);
    	long nTotalRows = spParent.GetTotalRowCount();
    	long nRowPos = GetRowPosition();
    	long nRows = GetRowCount();
    	if((nRowPos + nRows -1) >= nTotalRows)
    		return NULL;
    	long nCols = GetColCount();
    	*this = ((baseType)this)->GetResize(nRows+1, nCols);
    	return GetRowAt(nRows+1);
    }
     
    CAksRange CAksRange::AddLeftColumn()
    {
    	long nColPos = GetColPosition();
    	if(nColPos <= 1)
    		return NULL;
    	long nRows = GetRowCount();
    	long nCols = GetColCount();
    	CAksRange spThis = ((baseType)this)->GetOffset(0, -1);
    	*this = spThis->GetResize(nRows, nCols+1);
    	return GetColAt(1);
    }
     
    CAksRange CAksRange::AddRightColumn()
    {
    	CAksWorkSheet spParent = ((baseType)this)->GetWorksheet();
    	ATLASSERT(spParent);
    	long nTotalCols = spParent.GetTotalColCount();
    	long nColPos = GetColPosition();
    	long nCols = GetColCount();
    	if((nColPos + nCols -1) >= nTotalCols)
    		return NULL;
    	long nRows = GetRowCount();
    	*this = ((baseType)this)->GetResize(nRows, nCols+1);
    	return GetColAt(nCols+1);
    }
     
    bool CAksRange::RemoveTopRow()
    {
    	long nRows = GetRowCount();
    	if(nRows <= 1)
    		return false;
    	long nCols = GetColCount();
    	CAksRange spThis = ((baseType)this)->GetOffset(1, 0);
    	*this = spThis->GetResize(nRows-1, nCols);
    	return true;	
    }
     
    bool CAksRange::RemoveBottomRow()
    {
    	long nRows = GetRowCount();
    	if(nRows <= 1)
    		return false;
    	long nCols = GetColCount();
    	*this = ((baseType)this)->GetResize(nRows-1, nCols);
    	return true;
    }
     
    bool CAksRange::RemoveLeftColumn()
    {
    	long nCols = GetColCount();
    	if(nCols <= 1)
    		return false;
    	long nRows = GetRowCount();
    	CAksRange spThis = ((baseType)this)->GetOffset(0, 1);
    	*this = spThis->GetResize(nRows, nCols-1);
    	return true;
    }
     
    bool CAksRange::RemoveRightColumn()
    {
    	long nCols = GetColCount();
    	if(nCols <= 1)
    		return false;
    	long nRows = GetRowCount();
    	*this = ((baseType)this)->GetResize(nRows, nCols-1);
    	return true;
    }
     
    bool CAksRange::AutoResize(long nRows, long nCols)
    {
    	if(nRows < 1 || nCols < 1)
    		return false;
     
    	long nRowPos = GetRowPosition();
    	long nColPos = GetColPosition();
     
    	CAksWorkSheet spParent = ((baseType)this)->GetWorksheet();
    	ATLASSERT(spParent);
    	long nTotalRows = spParent.GetTotalRowCount();
    	long nTotalCols = spParent.GetTotalColCount();
     
    	if((nRowPos + nRows -1) > nTotalRows)
    		return false;
     
    	if((nColPos + nCols -1) > nTotalCols)
    		return false;
     
    	*this = ((baseType)this)->GetResize(nRows, nCols);
    	return true;
    }
     
    bool CAksRange::Move(long nOffsetRow, long nOffsetCol)
    {
    	CAksRange spCell = GetOffsetCellAt(1, 1, nOffsetRow, nOffsetCol);
    	if( !spCell )
    		return false;
     
    	long nRows = GetRowCount();
    	long nCols = GetColCount();
    	if( !spCell.AutoResize(nRows, nCols) )
    		return false;
     
    	*this = spCell;
    	return true;
    }
     
    CAksRange CAksRange::GetTopRow()
    {
    	return GetRowAt(1);
    }
     
    CAksRange CAksRange::GetBottomRow()
    {
    	long nRows = GetRowCount();
    	return GetRowAt(nRows);	
    }
     
    CAksRange CAksRange::GetLeftColumn()
    {
    	return GetColAt(1);
    }
     
    CAksRange CAksRange::GetRightColumn()
    {
    	long nCols = GetColCount();
    	return GetColAt(nCols);
    }
     
    int CAksRange::GetColumnWidth()
    {
    	return ((baseType)this)->GetColumnWidth();
    }
     
    void CAksRange::SetColumnWidth(int nWidth)
    {
    	((baseType)this)->PutColumnWidth(nWidth);
    }
     
    int CAksRange::GetColumnWidth(long nRow, long nCol)
    {
    	CAksRange spCell = GetCellAt(nRow, nCol);
    	if(spCell == NULL)
    		return -1;
     
    	return spCell.GetColumnWidth();
    }
     
    void CAksRange::SetColumnWidth(long nRow, long nCol, int nWidth)
    {
    	CAksRange spCell = GetCellAt(nRow, nCol);
    	if(spCell)
    		spCell.SetColumnWidth(nWidth);
    }
     
    int CAksRange::GetRowHeight()
    {
    	return ((baseType)this)->GetRowHeight();
    }
     
    void CAksRange::SetRowHeight(int nHeight)
    {
    	((baseType)this)->PutRowHeight(nHeight);
    }
     
    int CAksRange::GetRowHeight(long nRow, long nCol)
    {
    	CAksRange spCell = GetCellAt(nRow, nCol);
    	if(spCell == NULL)
    		return -1;
     
    	return spCell.GetRowHeight();
    }
     
    void CAksRange::SetRowHeight(long nRow, long nCol, int nHeight)
    {
    	CAksRange spCell = GetCellAt(nRow, nCol);
    	if(spCell)
    		spCell.SetRowHeight(nHeight);
    }
     
    bool CAksRange::HasMergeCells()  // true si cette rangée contient des cellules fusionnées
    {
    	return ((baseType)this)->GetMergeCells();
    }
     
    void CAksRange::PutMergeCells(bool bMerge)
    {
    	((baseType)this)->PutMergeCells(bMerge);
    }
     
    CAksRange CAksRange::GetMergeArea()  // retourne la rangée des cellules fusionnées
    {
    	return ((baseType)this)->GetMergeArea();
    }
     
    bool CAksRange::Merge(bool bByRow /*= false*/)
    {
    	HRESULT hr = ((baseType)this)->Merge(bByRow);
    	return (hr == S_OK)? true: false;
    }
     
    bool CAksRange::UnMerge()
    {
    	HRESULT hr = ((baseType)this)->UnMerge();
    	return (hr == S_OK)? true: false;
    }
     
    void CAksRange::PutBold(BOOL bBold)
    {
    	Excel::FontPtr spFont = ((baseType)this)->GetFont();
    	spFont->PutBold(bBold);
    }
     
    void CAksRange::PutSize(short nSize)
    {
    	Excel::FontPtr spFont = ((baseType)this)->GetFont();
    	spFont->PutSize(nSize);
    }
     
    void CAksRange::PutBordersLineStyle(Excel::XlLineStyle arg1)
    {
    	try
    	{
    		Excel::BordersPtr spBorders = ((baseType)this)->GetBorders();
    		Excel::BorderPtr spBorder = spBorders->GetItem(Excel::xlEdgeBottom);
    		spBorder->PutLineStyle(arg1);
    		spBorder = spBorders->GetItem(Excel::xlEdgeLeft);
    		spBorder->PutLineStyle(arg1);
    		spBorder = spBorders->GetItem(Excel::xlEdgeRight);
    		spBorder->PutLineStyle(arg1);
    		spBorder = spBorders->GetItem(Excel::xlEdgeTop);
    		spBorder->PutLineStyle(arg1);
    	}
    	catch(...)
    	{
    		ATLTRACE("An exception is catched in CAksRange::PutBordersLineStyle()\n");
    	}
    }
     
    void CAksRange::PutBordersGrid(Excel::XlLineStyle arg1)
    {
    	long nRows = GetRowCount();
    	long nCols = GetColCount();
    	for(long nRow = 1; nRow <= nRows; nRow++)
    	{
    		for(long nCol = 1; nCol <= nCols; nCol++)
    		{
    			CAksRange spCell = GetCellAt(nRow, nCol);
    			spCell.PutBordersLineStyle(arg1);
    		}
    	}
    }
     
    void CAksRange::PutWeight(Excel::XlBorderWeight arg1)
    {
    	Excel::BordersPtr spBorders = ((baseType)this)->GetBorders();
    	Excel::BorderPtr spBorder = spBorders->GetItem(Excel::xlEdgeBottom);
    	spBorder->PutWeight(arg1);
    	spBorder = spBorders->GetItem(Excel::xlEdgeLeft);
    	spBorder->PutWeight(arg1);
    	spBorder = spBorders->GetItem(Excel::xlEdgeRight);
    	spBorder->PutWeight(arg1);
    	spBorder = spBorders->GetItem(Excel::xlEdgeTop);
    	spBorder->PutWeight(arg1);
    }

  9. #29
    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
    et enfin la suite CAksRange
    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
     
    void CAksRange::PutColorIndex(short nIndex)
    {
    	Excel::InteriorPtr spInterior = ((baseType)this)->GetInterior();
    	spInterior->PutColorIndex(nIndex);
    }
     
    void CAksRange::SetHorizAlign(Excel::XlHAlign align)
    {
    	((baseType)this)->PutHorizontalAlignment(align);
    }
     
    Excel::XlHAlign CAksRange::GetHorizAlign()
    {
    	Excel::XlHAlign align = (Excel::XlHAlign)(int)((baseType)this)->GetHorizontalAlignment();
    	return align;
    }
     
    void CAksRange::SetVertAlign(Excel::XlVAlign align)
    {
    	((baseType)this)->PutVerticalAlignment(align);
    }
     
    Excel::XlVAlign CAksRange::GetVertAlign()
    {
    	Excel::XlVAlign align = (Excel::XlVAlign)(int)((baseType)this)->GetVerticalAlignment();
    	return align;
    }
     
    void CAksRange::SetColor(COLORREF color)
    {
    	Excel::InteriorPtr spInterior = ((baseType)this)->GetInterior();
    	spInterior->PutColor(color);
    }
     
    COLORREF CAksRange::GetColor()
    {
    	Excel::InteriorPtr spInterior = ((baseType)this)->GetInterior();
    	return spInterior->GetColor();
    }
     
    void CAksRange::SetNumberFormat(CString strNumberFormat)
    {
    	((baseType)this)->PutNumberFormat(strNumberFormat.GetString());
    }
     
    CString CAksRange::GetNumberFormat()
    {
    	CString strNumberFormat = ((baseType)this)->GetNumberFormat();
    	return strNumberFormat;
    }
     
    bool CAksRange::IsTextWraped()
    {
    	return ((baseType)this)->GetWrapText();
    }
     
    void CAksRange::WrapText(bool bWrap)
    {
    	((baseType)this)->PutWrapText(bWrap);
    }
     
    void CAksRange::PutFormula(CString strFormula)
    {
    	((baseType)this)->PutFormula(strFormula.GetString());
    }
     
    CString CAksRange::GetFormula()
    {
    	_bstr_t bstrVal = ((baseType)this)->GetFormula();
    	return CString(bstrVal.GetBSTR());
    }
     
    AKS::CAksVariant CAksRange::AutoFitColumns()
    {
    	Excel::RangePtr spCols = ((baseType)this)->GetEntireColumn();
    	return spCols->AutoFit();
    }
     
    AKS::CAksVariant CAksRange::AutoFitRows()
    {
    	Excel::RangePtr spRows = ((baseType)this)->GetEntireRow();
    	return spRows->AutoFit();
    }
     
    // Place la formule de sommation sur une colonne relative à spCols
    // typiquement à droite de spCols. (spCols = ensemble des colonnes)
    void CAksRange::PutColumnSumFormula(CAksRange spCols)
    {
    	if(spCols == NULL)
    		return;
     
    	CAksRange spTopRow = spCols.GetRowAt(1);
    	CString strFormula = _T("=");
    	long nColCount = spTopRow.GetColCount();
    	for(long j = 1; j <= nColCount; j++)
    	{
    		strFormula += spTopRow.GetLocalAddress(1, j);
    		if(j < nColCount)
    			strFormula += _T("+");
    	}
    	PutFormula(strFormula);
    }
     
    // Place la formule de sommation sur une ligne relative à spRows
    // typiquement en bas de spRows. (spRows = ensemble des lignes)
    void CAksRange::PutRowSumFormula(CAksRange spRows)
    {
    	if(spRows == NULL)
    		return;
     
    	CAksRange spRightCol = spRows.GetColAt(1);
    	CString strFormula = _T("=");
    	long nRowCount = spRightCol.GetRowCount();
    	for(long i = 1; i <= nRowCount; i++)
    	{
    		strFormula += spRightCol.GetLocalAddress(i, 1);
    		if(i < nRowCount)
    			strFormula += _T("+");
    	}
    	PutFormula(strFormula);
    }
     
    // Place la formule de moyenne sur une colonne relative à spCols
    // typiquement à droite de spCols. (spCols = ensemble des colonnes)
    void CAksRange::PutColumnMoyFormula(CAksRange spCols)
    {
    	if(spCols == NULL)
    		return;
     
    	CAksRange spTopRow = spCols.GetRowAt(1);
    	CString strFormula = _T("=(");
    	long nColCount = spTopRow.GetColCount();
    	for(long j = 1; j <= nColCount; j++)
    	{
    		strFormula += spTopRow.GetLocalAddress(1, j);
    		if(j < nColCount)
    			strFormula += _T("+");
    	}
    	strFormula += _T(")/");
    	CString strCount;
    	strCount.Format(_T("%ld"), nColCount);
    	strFormula += strCount;
    	PutFormula(strFormula);
    }
     
    // Place la formule de moyenne sur une ligne relative à spRows
    // typiquement en bas de spRows. (spRows = ensemble des lignes)
    void CAksRange::PutRowMoyFormula(CAksRange spRows)
    {
    	if(spRows == NULL)
    		return;
     
    	CAksRange spRightCol = spRows.GetColAt(1);
    	CString strFormula = _T("=(");
    	long nRowCount = spRightCol.GetRowCount();
    	for(long i = 1; i <= nRowCount; i++)
    	{
    		strFormula += spRightCol.GetLocalAddress(i, 1);
    		if(i < nRowCount)
    			strFormula += _T("+");
    	}
    	strFormula += _T(")/");
    	CString strCount;
    	strCount.Format(_T("%ld"), nRowCount);
    	strFormula += strCount;
    	PutFormula(strFormula);
    }
     
    void CAksRange::FindData(AKS::CAksVariant varData, long& nRowFound, long& nColFound)
    {
    	nRowFound = -1;
    	nColFound = -1;
     
    	if(varData.IsEmpty())
    		return;
     
    	CAksRange spTopLeft = GetTopLeft();
    	long nRowCount = GetRowCount();
    	long nColCount = GetColCount();
     
    	for(long nRow = 1; nRow <= nRowCount; nRow++)
    	{
    		for(long nCol = 1; nCol <= nColCount; nCol++)
    		{
    			CAksRange spCell = spTopLeft->GetOffset(nRow-1, nCol-1);
    			AKS::CAksVariant varValue = spCell.GetValue();
    			if(varData == varValue)
    			{
    				nRowFound = nRow;
    				nColFound = nCol;
    				return;
    			}
    		}
    	}
    }
     
    CAksRange CAksRange::FindRowRange(CString strData, long nFoundAtCol)
    {
    	long nCols = GetColCount();
    	if(strData.IsEmpty() || nFoundAtCol < 1 || nFoundAtCol > nCols)
    		return NULL;
     
    	long nRowFound = -1;
    	long nColFound = -1;
    	CAksRange spCol = GetColAt(nFoundAtCol);
    	spCol.FindData(strData, nRowFound, nColFound);
    	if(nRowFound != -1)
    		return GetRowAt(nRowFound);
    	else
    		return NULL;
    }
     
    CAksRange CAksRange::FindColRange(CString strData, long nFoundAtRow)
    {
    	long nRows = GetRowCount();
    	if(strData.IsEmpty() || nFoundAtRow < 1 || nFoundAtRow > nRows)
    		return NULL;
     
    	long nRowFound = -1;
    	long nColFound = -1;
    	CAksRange spRow = GetRowAt(nFoundAtRow);
    	spRow.FindData(strData, nRowFound, nColFound);
    	if(nColFound != -1)
    		return GetColAt(nColFound);
    	else
    		return NULL;
    }
     
    bool CAksRange::Sort(short XlSortOrientation, short XlSortOrder, long nOrientationIndex, VARTYPE vt)
    {
    	if(XlSortOrientation != Excel::xlSortRows && XlSortOrientation != Excel::xlSortColumns)
    		return false;
    	else if(XlSortOrder != Excel::xlAscending && XlSortOrder != Excel::xlDescending)
    		return false;
     
    	if(XlSortOrientation == Excel::xlSortRows)
    		return SortRows(XlSortOrder, nOrientationIndex, vt);
    	else
    		return SortCols(XlSortOrder, nOrientationIndex, vt);
    }
     
    bool CAksRange::SortCols(short XlSortOrder, long nRowIndex, VARTYPE vt)
    {
    	if(XlSortOrder != Excel::xlAscending && XlSortOrder != Excel::xlDescending)
    		return false;
    	CAksRange spRow = GetRowAt(nRowIndex);
    	if(spRow == NULL)
    		return false;
     
    	long nRows = GetRowCount();
    	long nCols = spRow.GetColCount();
    	for(long nCurIndex = 1; nCurIndex <= nCols; nCurIndex++)
    	{
    		AKS::CAksDataSet dsCurColData;
    		// we convert to CString because CurValue as CAksVariant is an IDispatch by default
    		CString strCurValue = spRow.GetItem(1, nCurIndex);  // that don't keep the same cell value while moving columns
    		long nPrevIndex = nCurIndex-1;
    		for(; nPrevIndex >= 1; nPrevIndex--)
    		{
    			AKS::CAksVariant PrevValue = spRow.GetItem(1, nPrevIndex);
    			AKS::CAksVariant CurValue = strCurValue; // we retrieve the CurValue as a CAksVariant
    			CurValue.m_vtOperation = vt;
    			if((XlSortOrder == Excel::xlAscending) && (CurValue >= PrevValue) )
    				break;
    			else if((XlSortOrder == Excel::xlDescending) && (CurValue <= PrevValue) )
    				break;
     
    			if(dsCurColData.IsEmpty())
    			{
    				CAksRange spCurCol = GetColAt(nCurIndex);
    				spCurCol.GetVerticalArrayDataSet(nRows, dsCurColData, vt);
    			}
    			AKS::CAksDataSet dsColData;
    			CAksRange spCol1 = GetColAt(nPrevIndex);
    			spCol1.GetVerticalArrayDataSet(nRows, dsColData, vt);
    			CAksRange spCol2 = GetColAt(nPrevIndex+1);
    			spCol2.PutVerticalArrayDataSet(dsColData);
    		}
     
    		if( !dsCurColData.IsEmpty() )
    		{
    			CAksRange spCurCol = GetColAt(nPrevIndex+1);
    			spCurCol.PutVerticalArrayDataSet(dsCurColData);
    		}
    	}
    	return true;
    }
     
    bool CAksRange::SortRows(short XlSortOrder, long nColIndex, VARTYPE vt)
    {
    	if(XlSortOrder != Excel::xlAscending && XlSortOrder != Excel::xlDescending)
    		return false;
    	CAksRange spCol = GetColAt(nColIndex);
    	if(spCol == NULL)
    		return false;
     
    	long nCols = GetColCount();
    	long nRows = spCol.GetRowCount();
    	for(long nCurIndex = 1; nCurIndex <= nRows; nCurIndex++)
    	{
    		AKS::CAksDataSet dsCurRowData;
    		// we convert to CString because CurValue as CAksVariant is an IDispatch by default
    		CString strCurValue = spCol.GetItem(nCurIndex, 1);  // that don't keep the same cell value while moving rows
    		long nPrevIndex = nCurIndex-1;
    		for(; nPrevIndex >= 1; nPrevIndex--)
    		{
    			AKS::CAksVariant PrevValue = spCol.GetItem(nPrevIndex, 1);
    			AKS::CAksVariant CurValue = strCurValue; // we retrieve the CurValue as a CAksVariant
    			CurValue.m_vtOperation = vt;
    			if((XlSortOrder == Excel::xlAscending) && (CurValue >= PrevValue) )
    				break;
    			else if((XlSortOrder == Excel::xlDescending) && (CurValue <= PrevValue) )
    				break;
     
    			if(dsCurRowData.IsEmpty())
    			{
    				CAksRange spCurRow = GetRowAt(nCurIndex);
    				spCurRow.GetHorizontalArrayDataSet(nCols, dsCurRowData, vt);
    			}
    			AKS::CAksDataSet dsRowData;
    			CAksRange spRow1 = GetRowAt(nPrevIndex);
    			spRow1.GetHorizontalArrayDataSet(nCols, dsRowData, vt);
    			CAksRange spRow2 = GetRowAt(nPrevIndex+1);
    			spRow2.PutHorizontalArrayDataSet(dsRowData);
    		}
     
    		if( !dsCurRowData.IsEmpty() )
    		{
    			CAksRange spCurRow = GetRowAt(nPrevIndex+1);
    			spCurRow.PutHorizontalArrayDataSet(dsCurRowData);
    		}
    	}
    	return true;
    }
     
    void CAksRange::PutColumnFormula(CAksRange spCols, CString strFormula)
    {
    	if(spCols == NULL || strFormula.IsEmpty() || strFormula.GetAt(0) != '=')
    		return;
     
    	CAksRange spTopRow = spCols.GetRowAt(1);
    	long nColCount = spTopRow.GetColCount();
    	for(long j = 1; j <= nColCount; j++)
    	{
    		CString strVar;
    		strVar.Format(_T("$%d"), j);
    		CString strAddr = spTopRow.GetLocalAddress(1, j);
    		strFormula.Replace(strVar, strAddr);
    	}
    	PutFormula(strFormula);
    }
     
    void CAksRange::PutRowFormula(CAksRange spRows, CString strFormula)
    {
    	if(spRows == NULL || strFormula.IsEmpty() || strFormula.GetAt(0) != '=')
    		return;
     
    	CAksRange spLeftCol = spRows.GetColAt(1);
    	long nRowCount = spLeftCol.GetRowCount();
    	for(long i = 1; i <= nRowCount; i++)
    	{
    		CString strVar;
    		strVar.Format(_T("$%d"), i);
    		CString strAddr = spLeftCol.GetLocalAddress(i, 1);
    		strFormula.Replace(strVar, strAddr);
    	}
    	PutFormula(strFormula);
    }
     
    Excel::RangePtr CAksRange::PutHorizontalArrayDataSet(AKS::CAksDataSet& dsArray)
    {
    	AKS::Utility::CAksVariantArray VariantArray;
    	VariantArray.ReadDataSet(dsArray);
    	return PutHorizontalArray(VariantArray);
    }
     
    Excel::RangePtr CAksRange::PutHorizontalArrayDataSet(LPSTR* pszRowData, long dwLen)
    {
    	if(pszRowData == NULL || dwLen <= 0)
    		return NULL;
    	AKS::Utility::CAksVariantArray VariantArray;
    	VariantArray.SetSize(dwLen);
    	for(long i = 0; i < dwLen; i++)
    		VariantArray.SetAt(i, pszRowData[i]);
    	return PutHorizontalArray(VariantArray);
    }
     
    Excel::RangePtr CAksRange::PutHorizontalArray(AKS::Utility::CAksVariantArray& VariantArray)
    {
    	Excel::RangePtr spTopLeft = GetTopLeft();
    	Excel::RangePtr spCell;
    	long nCols = (long)VariantArray.GetCount();
    	for(long nCol = 0; nCol < nCols; nCol++)
    	{
    		AKS::CAksVariant varValue = VariantArray.GetAt(nCol);
    		spCell = spTopLeft->GetOffset(0, nCol);
    		spCell->PutValue2(varValue);
    	}
    	return spCell;
    }
     
    Excel::RangePtr CAksRange::PutVerticalArrayDataSet(AKS::CAksDataSet& dsArray)
    {
    	AKS::Utility::CAksVariantArray VariantArray;
    	VariantArray.ReadDataSet(dsArray);
    	return PutVerticalArray(VariantArray);
    }
     
    Excel::RangePtr CAksRange::PutVerticalArrayDataSet(LPSTR* pszColData, long dwLen)
    {
    	if(pszColData == NULL || dwLen <= 0)
    		return NULL;
    	AKS::Utility::CAksVariantArray VariantArray;
    	VariantArray.SetSize(dwLen);
    	for(long i = 0; i < dwLen; i++)
    		VariantArray.SetAt(i, pszColData[i]);
    	return PutVerticalArray(VariantArray);
    }
     
    Excel::RangePtr CAksRange::PutVerticalArray(AKS::Utility::CAksVariantArray& VariantArray)
    {
    	Excel::RangePtr spTopLeft = GetTopLeft();
    	Excel::RangePtr spCell;
    	long nRows = (long)VariantArray.GetCount();
    	for(long nRow = 0; nRow < nRows; nRow++)
    	{
    		AKS::CAksVariant varValue = VariantArray.GetAt(nRow);
    		spCell = spTopLeft->GetOffset(nRow, 0);
    		spCell->PutValue2(varValue);
    	}
    	return spCell;
    }
     
    Excel::RangePtr CAksRange::PutMatrixDataSet(long nRowBound, long nColBound, AKS::CAksDataSet& dsMatrix)
    {
    	Excel::RangePtr spTopLeft = GetTopLeft();
    	Excel::RangePtr spCell;
    	POSITION pos = dsMatrix.GetFirstPosition();
    	for(long nRow = 0; nRow < nRowBound; nRow++)
    	{
    		for(long nCol = 0; nCol < nColBound; nCol++)
    		{
    			if(pos == NULL)
    				return spCell;
     
    			CStringA strKey;
    			CStringA strValue;
    			dsMatrix.GetNext(pos, strKey, strValue);
    			spCell = spTopLeft->GetOffset(nRow, nCol);
    			spCell->PutValue2(strValue.GetString());
    		}
    	}
    	return spCell;
    }
     
    Excel::RangePtr CAksRange::GetHorizontalArrayDataSet(long nCols, AKS::CAksDataSet& dsArray, VARTYPE vt)
    {
    	if(nCols <= 0)
    		return NULL;
    	AKS::Utility::CAksVariantArray VariantArray;
    	VariantArray.SetSize(nCols);
    	Excel::RangePtr spCell = GetHorizontalArray(VariantArray);
    	if(spCell)
    	{
    		VariantArray.m_vtOperation = vt;
    		VariantArray.WriteDateSet(dsArray);
    	}
    	return spCell;
    }
     
    Excel::RangePtr CAksRange::GetHorizontalArray(AKS::Utility::CAksVariantArray& VariantArray)
    {
    	Excel::RangePtr spTopLeft = GetTopLeft();
    	Excel::RangePtr spCell;
    	long nCols = (long)VariantArray.GetSize();
    	for(long nCol = 0; nCol < nCols; nCol++)
    	{
    		spCell = spTopLeft->GetOffset(0, nCol);
    		AKS::CAksVariant varValue = spCell->GetValue2();
    		VariantArray.SetAt(nCol, varValue);
    	}
    	return spCell;
    }
     
    Excel::RangePtr CAksRange::GetVerticalArrayDataSet(long nRows, AKS::CAksDataSet& dsArray, VARTYPE vt)
    {
    	if(nRows <= 0)
    		return NULL;
    	AKS::Utility::CAksVariantArray VariantArray;
    	VariantArray.SetSize(nRows);
    	Excel::RangePtr spCell = GetVerticalArray(VariantArray);
    	if(spCell)
    	{
    		VariantArray.m_vtOperation = vt;
    		VariantArray.WriteDateSet(dsArray);
    	}
    	return spCell;
    }
     
    Excel::RangePtr CAksRange::GetVerticalArray(AKS::Utility::CAksVariantArray& VariantArray)
    {
    	Excel::RangePtr spTopLeft = GetTopLeft();
    	Excel::RangePtr spCell;
    	long nRows = (long)VariantArray.GetSize();
    	for(long nRow = 0; nRow < nRows; nRow++)
    	{
    		spCell = spTopLeft->GetOffset(nRow, 0);
    		AKS::CAksVariant varValue = spCell->GetValue2();
    		VariantArray.SetAtGrow(nRow, varValue);
    	}
    	return spCell;
    }
     
    Excel::RangePtr CAksRange::GetMatrixDataSet(long nRowBound, long nColBound, AKS::CAksDataSet& dsMatrix, VARTYPE vt)
    {
    	dsMatrix.Reset();
    	long nIndex = 0;
    	Excel::RangePtr spTopLeft= GetTopLeft();
    	Excel::RangePtr spCell;
    	for(long nRow = 0; nRow < nRowBound; nRow++)
    	{
    		for(long nCol = 0; nCol < nColBound; nCol++)
    		{
    			spCell = spTopLeft->GetOffset(nRow, nCol);
    			AKS::CAksVariant varValue = spCell->GetItem(1, 1);
    			varValue.m_vtOperation = vt;
    			dsMatrix.AddVariant(nIndex, varValue);
    		}
    	}
    	return spCell;
    }
     
    Excel::RangePtr CAksRange::PutHorizontalArrayValues(AKS::Utility::CAksSafeArray& safeArray)
    {
    	long nUpperBound = 0;
    	safeArray.GetUBound(1, &nUpperBound);
     
    	long nLowerBound = 0;
    	safeArray.GetLBound(1, &nLowerBound);
     
    	Excel::RangePtr spTopLeft = GetTopLeft();
    	Excel::RangePtr spCell;
    	for(long nIndex = nLowerBound; nIndex <= nUpperBound; nIndex++ )
    	{
    		VARIANT value;
    		long index[1];
    		index[0] = nIndex;
    		safeArray.GetElement(index, &value);
    		spCell = spTopLeft->GetOffset(0, nIndex);
    		switch(value.vt)
    		{
    		case VT_BSTR:
    			spCell->PutValue2(value.bstrVal);
    			break;
     
    		case VT_R8:
    			spCell->PutValue2(value.dblVal);
    			break;
    		}
    	}
    	return spCell;
    }
     
    Excel::RangePtr CAksRange::PutVerticalArrayValues(AKS::Utility::CAksSafeArray& safeArray)
    {
    	long nUpperBound = 0;
    	safeArray.GetUBound(1, &nUpperBound);
     
    	long nLowerBound = 0;
    	safeArray.GetLBound(1, &nLowerBound);
     
    	Excel::RangePtr spTopLeft = GetTopLeft();
    	Excel::RangePtr spCell;
    	for(long nIndex = nLowerBound; nIndex <= nUpperBound; nIndex++ )
    	{
    		VARIANT value;
    		long index[1];
    		index[0] = nIndex;
    		safeArray.GetElement(index, &value);
    		spCell = spTopLeft->GetOffset(nIndex, 0);
    		switch(value.vt)
    		{
    		case VT_BSTR:
    			spCell->PutValue2(value.bstrVal);
    			break;
     
    		case VT_R8:
    			spCell->PutValue2(value.dblVal);
    			break;
    		}
    	}
    	return spCell;
    }
     
    Excel::RangePtr CAksRange::PutMatrixValues(AKS::Utility::CAksSafeArray& safeArray)
    {
    	long nUpperRowBound = 0;
    	long nUpperColBound = 0;
    	safeArray.GetUBound(1, &nUpperRowBound);
    	safeArray.GetUBound(2, &nUpperColBound);
     
    	long nLowerRowBound = 0;
    	long nLowerColBound = 0;
    	safeArray.GetLBound(1, &nLowerRowBound);
    	safeArray.GetLBound(2, &nLowerColBound);
     
    	Excel::RangePtr spTopLeft = GetTopLeft();
    	Excel::RangePtr spCell;
    	for(long nRow = nLowerRowBound; nRow <= nUpperRowBound; nRow++)
    	{
    		for(long nCol = nLowerColBound; nCol <= nUpperColBound; nCol++)
    		{
    			VARIANT value;
    			long index[2];
    			index[0] = nRow;
    			index[1] = nCol;
    			safeArray.GetElement(index, &value);
    			spCell = spTopLeft->GetOffset(nRow, nCol);
    			switch(value.vt)
    			{
    			case VT_BSTR:
    				spCell->PutValue2(value.bstrVal);
    				break;
     
    			case VT_R8:
    				spCell->PutValue2(value.dblVal);
    				break;
    			}
    		}
    	}
    	return spCell;
    }
     
    AKS::CAksVariant CAksRange::Clear() // Clears the entire object. 
    {
    	return ((baseType)this)->Clear();
    }
     
    AKS::CAksVariant CAksRange::ClearContents()  // Clears the formulas from the range.
    {
    	return ((baseType)this)->ClearContents();
    }
     
    void CAksRange::CopyRange(CAksRange spSource)
    {
    	if(spSource == NULL)
    		return;
     
    	long nRows = spSource.GetRowCount();
    	long nCols = spSource.GetColCount();
     
    	for(long nRow = 1; nRow <= nRows; nRow++)
    	{
    		for(long nCol = 1; nCol <= nCols; nCol++)
    		{
    			CAksVariant value = spSource.GetItem(nRow, nCol);
    			PutOffsetItem(1, 1, nRow-1, nCol-1, value);
    		}
    	}
    }

  10. #30
    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
    Bon,

    Définit un fichier en-tête d'Excel 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
     
    // fichier Aks.Excel.h
     
     
    #pragma once
     
     
    #include "AksVariant.h"
    #include "AksDataSet.h"
    #include "AksSafeArray.h"
    #include "AksComPtrT.h"
     
    #include "OfficeImport.h"
    #include "ExcelImport.h"
     
    #include "AksRange.h"
    #include "AksWorkSheet.h"
    #include "AksWorkSheets.h"
    #include "AksWorkBook.h"
    #include "AksWorkBooks.h"
    #include "AksExcelApp.h"
    Que tu vas insérer après le stdafx.h de tes sources *.cpp
    comme par exemple
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    #include "stdafx.h"
    #include "Aks.Excel.h"
    #include "TonFichierEntête.h"
    
    using namespace AKS::Automation::AksExcel;
    
    // tes sources
    Je crois que tu as maintenant toutes les sources

    AksSafeArray.cpp
    AksRange.cpp
    AksWorkSheet.cpp
    AksWorkSheets.cpp
    AksWorkBook.cpp
    AksWorkBooks.cpp
    AksExcelApp.cpp

    Essaie de compiler et donne moi la suite

    Pour utiliser la version d'Excel 2007 tu ajoutes ces lignes dans le stdafx.h de ton projet
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
     
    #define EXCEL12	// use MS Excel 2007
    //#define FRA
    //#define Program_Files_x86
    #include "ExcelImport.h"

  11. #31
    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
    Maintenant ton problème
    Citation Envoyé par tallent_e
    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’):


    Citation:
    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
    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
     
    #include "stdafx.h"
    #include "Aks.Excel.h"
     
     
    using namespace AKS::Automation::AksExcel;
     
    void Demo()
    {
    	try
    	{
    		CAksExcelApp spExcelApp;
     
    		// Crée une instance d'excel avec la version par défaut
    		// pour une version explicite ==> EXCEL_APPLICATION_2007 à la place de EXCEL_APPLICATION
    		HRESULT hr = spExcelApp.CreateInstance(EXCEL_APPLICATION);
    		if (FAILED(hr))
    		{
    			CString strError = _T("L'application Microsoft Excel 2003 ou 2007 est abscente sur l'ordinateur cible.");
    			throw strError;
    		}
     
    		ASSERT(spExcelApp != NULL);
     
    		CString strExcelVersion = spExcelApp.GetVersion();
    		int nMajor = atoi(CStringA(strExcelVersion).Left(2).GetString());
    		bool bUseExcel2007 = (nMajor >= 12);
     
    		if( !bUseExcel2007 ) // Excel 2007 ???
    		{
    			if(spExcelApp)
    				spExcelApp.Close();
     
    			if(spExcelApp)
    				spExcelApp.Release();
    		}
     
    		// Ouvre le classeur Excel
    		CAksWorkBook spWorkBook = spExcelApp.OpenWorkBook(_T("C:\\Users\\Édouard\\Desktop\\test.xlsx"));
    		if( spWorkBook == NULL )
    		{
    			CString strError = _T("Fichier excel non trouvé à l'emplacement spécifié");
    			throw strError;
    		}
     
    		// Ouvre une feuille par son nom
    		CAksWorkSheet spWorkSheet = spWorkBook.OpenWorkSheet(_T("Sheet1"));
    		if( spWorkSheet == NULL )
    		{
    			CString strError = _T("Le classeur excel n'a pas de feuille \"Sheet1\"");
    			throw strError;
    		}
     
    		// Obtient une rangée de 3 colonnes et d'un nombre de lignes non vide à partir de A1
    		CAksRange spRange = spWorkSheet.GetLimitRowRangeAt(_T("A1"), 3);
     
    		// 3 Vecteurs de rangées
    		CAksRange spRangeCol1 = spRange.GetColAt(1);
    		CAksRange spRangeCol2 = spRange.GetColAt(2);
    		CAksRange spRangeCol3 = spRange.GetColAt(3);
     
    		// extrait la deuxième ligne du vecteur 2
    		long nValue = spRangeCol2.GetItem(2, 1);
     
    		// ou obtient un vecteur de variant
    		AKS::Utility::CAksVariantArray VariantArray;
     
    		VariantArray.SetSize(spRangeCol3.GetRowCount());
     
    		spRangeCol3.GetVerticalArray(VariantArray);
     
    		// extrait la 4 ième ligne du vecteur 2
    		long nValue2 = VariantArray[4];
    		// ...
     
    		// ou bien je travaille avec la rangée comme une matrice 
    		// extrait l'élément à la ligne 3 et colonne 2 à partir de A1
    		long nValue3 = spRange.GetItem(3, 2);
     
    		// si je veux modifier à la ligne 3 et colonne 2 à partir de A1
    		spRange.PutItem(3, 2, _T("Je met du text à la place d'un integer"));
     
    		// Je sauve
    		spWorkBook.Save();
     
    		// Je ferme le classeur
    		spWorkBook.Close();
    	}
     
    	catch(CString strMsg)
    	{
    		AfxMessageBox(strMsg, MB_ICONSTOP);
    	}
     
    }

  12. #32
    Membre confirmé
    Inscrit en
    Novembre 2010
    Messages
    176
    Détails du profil
    Informations forums :
    Inscription : Novembre 2010
    Messages : 176
    Par défaut fichiers manquants !
    bonsoir gabrielly.

    j'ai tout bien suivi à la lettre (enfin, je crois ...)

    en compilant, visual c++ , dans AksDataSet.h , me dit qu'il ne trouve pas les deux fichiers :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    #include <atlcoll.h>
    #include <atlutil.h>
    .. heureusement qu'il ne les trouve pas, parce que je ne les ai pas !

    mais comment faire alors ?

  13. #33
    Membre confirmé
    Inscrit en
    Novembre 2010
    Messages
    176
    Détails du profil
    Informations forums :
    Inscription : Novembre 2010
    Messages : 176
    Par défaut j'ai un problème avec AksVariant.h
    bonsoir

    j'ai tout revérifié mes fichiers.

    en compilant j'obtiens un certain nombre d'erreurs en lien avec le fichier AksVariant.h

    par exemple :

    1>------ Build started: Project: ReadInExcel, Configuration: Debug Win32 ------
    1> stdafx.cpp
    1>c:\users\édouard\documents\visual studio 2010\projects\readinexcel\aksvariant.h(77): error C2061: syntax error : identifier 'COleDateTime'
    1> c:\users\édouard\documents\visual studio 2010\projects\readinexcel\aksvariant.h(531) : see reference to class template instantiation 'AKS::CCastingVariant<T>' being compiled
    1>c:\users\édouard\documents\visual studio 2010\projects\readinexcel\aksvariant.h(77): error C2535: 'AKS::CCastingVariant<T>::CCastingVariant(void) throw()' : member function already defined or declared
    1> c:\users\édouard\documents\visual studio 2010\projects\readinexcel\aksvariant.h(16) : see declaration of 'AKS::CCastingVariant<T>::CCastingVariant'
    1>c:\users\édouard\documents\visual studio 2010\projects\readinexcel\aksvariant.h(107): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
    1>c:\users\édouard\documents\visual studio 2010\projects\readinexcel\aksvariant.h(107): error C2143: syntax error : missing ',' before '&'
    1>c:\users\édouard\documents\visual studio 2010\projects\readinexcel\aksvariant.h(113): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
    1>c:\users\édouard\documents\visual studio 2010\projects\readinexcel\aksvariant.h(113): error C2143: syntax error : missing ',' before '&'
    1>c:\users\édouard\documents\visual studio 2010\projects\readinexcel\aksvariant.h(113): error C2535: 'AKS::CCastingVariant<T>::CCastingVariant(const int)' : member function already defined or declared
    1> c:\users\édouard\documents\visual studio 2010\projects\readinexcel\aksvariant.h(107) : see declaration of 'AKS::CCastingVariant<T>::CCastingVariant'
    1>c:\users\édouard\documents\visual studio 2010\projects\readinexcel\aksvariant.h(167): error C2535: 'AKS::CCastingVariant<T>::CCastingVariant(const int)' : member function already defined or declared
    1> c:\users\édouard\documents\visual studio 2010\projects\readinexcel\aksvariant.h(107) : see declaration of 'AKS::CCastingVariant<T>::CCastingVariant'
    1>c:\users\édouard\documents\visual studio 2010\projects\readinexcel\aksvariant.h(207): error C2833: 'operator CStringA' is not a recognized operator or type
    1>c:\users\édouard\documents\visual studio 2010\projects\readinexcel\aksvariant.h(207): error C2059: syntax error : 'newline'
    j'ai uploadé mon projet zippé sur le net. il est trop gros pour être téléchargé sur developpez.net (qui, à côté de cela est un site génial, pas d'embrouille Mr l'Administrateur ) , alors je l'ai mis là :
    https://docs.google.com/leaf?id=0B4c...M2IwOGE3&hl=en

    j'espère avoir un coup de main encore une fois , parce que là, c'est too much pour moi.

    merci !
    édouard

  14. #34
    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,

    Tu m'avais dit que tu as la version express
    Est-ce que tu peux télécharger la version d'essaie édition professionnelle?
    ça pourra résoudre un grand nombre de problèmes.

  15. #35
    Membre confirmé
    Inscrit en
    Novembre 2010
    Messages
    176
    Détails du profil
    Informations forums :
    Inscription : Novembre 2010
    Messages : 176
    Par défaut va pour le visual c++ 2010 essai
    je vais installé la version d'essai de visual c++.

    m'enfin bon, c'est dommage parce que cet essai est par nature limité dans le temps. ( pleaaaasse señor microsoft offre moi une licence, je suis un brave type quoi !
    ) .

    ...

    édouard

  16. #36
    Membre confirmé
    Inscrit en
    Novembre 2010
    Messages
    176
    Détails du profil
    Informations forums :
    Inscription : Novembre 2010
    Messages : 176
    Par défaut le visual c++ ultimate ne résoud pas mon pb
    bonjour !
    j'ai installé la version d'essai de visual c++ ultimate. c'est énorme !
    en compilant mon projet, j'ai toujours plein de messages d'érreur du style :
    See declaration of 'AKS::CCastingVariant<T>::CCastingVariant

  17. #37
    Membre confirmé
    Inscrit en
    Novembre 2010
    Messages
    176
    Détails du profil
    Informations forums :
    Inscription : Novembre 2010
    Messages : 176
    Par défaut ... toujours rien
    bonsoir gabrielly !
    et bien écoutez, je suis désolé que çà ne fonctionne toujours pas.
    je ne suis pas découragé, çà va bien finir par fonctionner !

  18. #38
    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
    Montre moi les messages d'erreurs
    et puis pour le type de projet
    Crée un Projet MFC Application,
    Dans ton cas une application de type boite de dialogue suffit

  19. #39
    Membre confirmé
    Inscrit en
    Novembre 2010
    Messages
    176
    Détails du profil
    Informations forums :
    Inscription : Novembre 2010
    Messages : 176
    Par défaut unsuccessfulbuild !
    bonjour gabrielly
    voici les erreurs, selon mr visual blingbling 2010



    1>------ Build started: Project: ReadInExcel, Configuration: Debug Win32 ------
    1>Build started 21/11/2010 17:15:05.
    1>InitializeBuildStatus:
    1> Touching "Debug\ReadInExcel.unsuccessfulbuild".
    1>ClCompile:
    1> stdafx.cpp
    1>c:\users\édouard\documents\visual studio 2010\projects\readinexcel\aksvariant.h(77): error C2061: syntax error : identifier 'COleDateTime'
    1> c:\users\édouard\documents\visual studio 2010\projects\readinexcel\aksvariant.h(531) : see reference to class template instantiation 'AKS::CCastingVariant<T>' being compiled
    1>c:\users\édouard\documents\visual studio 2010\projects\readinexcel\aksvariant.h(77): error C2535: 'AKS::CCastingVariant<T>::CCastingVariant(void) throw()' : member function already defined or declared
    1> c:\users\édouard\documents\visual studio 2010\projects\readinexcel\aksvariant.h(16) : see declaration of 'AKS::CCastingVariant<T>::CCastingVariant'
    1>c:\users\édouard\documents\visual studio 2010\projects\readinexcel\aksvariant.h(107): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
    1>c:\users\édouard\documents\visual studio 2010\projects\readinexcel\aksvariant.h(107): error C2143: syntax error : missing ',' before '&'
    1>c:\users\édouard\documents\visual studio 2010\projects\readinexcel\aksvariant.h(113): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
    1>c:\users\édouard\documents\visual studio 2010\projects\readinexcel\aksvariant.h(113): error C2143: syntax error : missing ',' before '&'
    1>c:\users\édouard\documents\visual studio 2010\projects\readinexcel\aksvariant.h(113): error C2535: 'AKS::CCastingVariant<T>::CCastingVariant(const int)' : member function already defined or declared
    1> c:\users\édouard\documents\visual studio 2010\projects\readinexcel\aksvariant.h(107) : see declaration of 'AKS::CCastingVariant<T>::CCastingVariant'
    1>c:\users\édouard\documents\visual studio 2010\projects\readinexcel\aksvariant.h(167): error C2535: 'AKS::CCastingVariant<T>::CCastingVariant(const int)' : member function already defined or declared
    1> c:\users\édouard\documents\visual studio 2010\projects\readinexcel\aksvariant.h(107) : see declaration of 'AKS::CCastingVariant<T>::CCastingVariant'
    1>c:\users\édouard\documents\visual studio 2010\projects\readinexcel\aksvariant.h(207): error C2833: 'operator CStringA' is not a recognized operator or type
    1>c:\users\édouard\documents\visual studio 2010\projects\readinexcel\aksvariant.h(207): error C2059: syntax error : 'newline'
    1>c:\users\édouard\documents\visual studio 2010\projects\readinexcel\aksvariant.h(208): error C2334: unexpected token(s) preceding '{'; skipping apparent function body
    1>c:\users\édouard\documents\visual studio 2010\projects\readinexcel\aksvariant.h(237): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
    1>c:\users\édouard\documents\visual studio 2010\projects\readinexcel\aksvariant.h(237): error C2143: syntax error : missing ',' before '&'
    1>c:\users\édouard\documents\visual studio 2010\projects\readinexcel\aksvariant.h(243): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
    1>c:\users\édouard\documents\visual studio 2010\projects\readinexcel\aksvariant.h(243): error C2143: syntax error : missing ',' before '&'
    1>c:\users\édouard\documents\visual studio 2010\projects\readinexcel\aksvariant.h(244): error C2535: 'AKS::CCastingVariant<T> &AKS::CCastingVariant<T>::operator =(const int)' : member function already defined or declared
    1> c:\users\édouard\documents\visual studio 2010\projects\readinexcel\aksvariant.h(237) : see declaration of 'AKS::CCastingVariant<T>::operator ='
    1>c:\users\édouard\documents\visual studio 2010\projects\readinexcel\aksvariant.h(255): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
    1>c:\users\édouard\documents\visual studio 2010\projects\readinexcel\aksvariant.h(255): error C2143: syntax error : missing ',' before '&'
    1>c:\users\édouard\documents\visual studio 2010\projects\readinexcel\aksvariant.h(256): error C2535: 'AKS::CCastingVariant<T> &AKS::CCastingVariant<T>::operator =(const int)' : member function already defined or declared
    1> c:\users\édouard\documents\visual studio 2010\projects\readinexcel\aksvariant.h(237) : see declaration of 'AKS::CCastingVariant<T>::operator ='
    1>c:\users\édouard\documents\visual studio 2010\projects\readinexcel\aksdataset.h(948): error C2061: syntax error : identifier 'COleDateTime'
    1>c:\users\édouard\documents\visual studio 2010\projects\readinexcel\aksdataset.h(1330): error C2061: syntax error : identifier 'COleDateTime'
    1>c:\users\édouard\documents\visual studio 2010\projects\readinexcel\aksdataset.h(1544): error C2061: syntax error : identifier 'COleDateTime'
    1>c:\users\édouard\documents\visual studio 2010\projects\readinexcel\aksdataset.h(950): error C2065: 'oleDate' : undeclared identifier
    1>c:\users\édouard\documents\visual studio 2010\projects\readinexcel\aksdataset.h(950): error C2228: left of '.m_dt' must have class/struct/union
    1> type is ''unknown-type''
    1>c:\users\édouard\documents\visual studio 2010\projects\readinexcel\aksvariant.h(77): error C2061: syntax error : identifier 'COleDateTime'
    1> c:\users\édouard\documents\visual studio 2010\projects\readinexcel\aksdataset.h(1044) : see reference to class template instantiation 'AKS::CCastingVariant<T>' being compiled
    1> with
    1> [
    1> T=void
    1> ]
    1>c:\users\édouard\documents\visual studio 2010\projects\readinexcel\aksvariant.h(77): error C2535: 'AKS::CCastingVariant<T>::CCastingVariant(void) throw()' : member function already defined or declared
    1> with
    1> [
    1> T=void
    1> ]
    1> c:\users\édouard\documents\visual studio 2010\projects\readinexcel\aksvariant.h(16) : see declaration of 'AKS::CCastingVariant<T>::CCastingVariant'
    1> with
    1> [
    1> T=void
    1> ]
    1>c:\users\édouard\documents\visual studio 2010\projects\readinexcel\aksvariant.h(255): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
    1>c:\users\édouard\documents\visual studio 2010\projects\readinexcel\aksvariant.h(255): error C2143: syntax error : missing ',' before '&'
    1>c:\users\édouard\documents\visual studio 2010\projects\readinexcel\aksdataset.h(1068): error C3861: 'COleDateTime': identifier not found
    1>c:\users\édouard\documents\visual studio 2010\projects\readinexcel\aksdataset.h(1332): error C2065: 'oleDate' : undeclared identifier
    1>c:\users\édouard\documents\visual studio 2010\projects\readinexcel\aksdataset.h(1549): error C2065: 'pValue' : undeclared identifier
    1>c:\users\édouard\documents\visual studio 2010\projects\readinexcel\aksdataset.h(1552): error C2065: 'pContext' : undeclared identifier
    1>c:\users\édouard\documents\visual studio 2010\projects\readinexcel\aksdataset.h(1554): error C2065: 'pValue' : undeclared identifier
    1>c:\users\édouard\documents\visual studio 2010\projects\readinexcel\aksvariant.h(77): error C2061: syntax error : identifier 'COleDateTime'
    1> c:\users\édouard\documents\visual studio 2010\projects\readinexcel\aksdataset.h(2018) : see reference to class template instantiation 'AKS::CCastingVariant<T>' being compiled
    1> with
    1> [
    1> T=AKS::CAksDataSet
    1> ]
    1>c:\users\édouard\documents\visual studio 2010\projects\readinexcel\aksvariant.h(77): error C2535: 'AKS::CCastingVariant<T>::CCastingVariant(void) throw()' : member function already defined or declared
    1> with
    1> [
    1> T=AKS::CAksDataSet
    1> ]
    1> c:\users\édouard\documents\visual studio 2010\projects\readinexcel\aksvariant.h(16) : see declaration of 'AKS::CCastingVariant<T>::CCastingVariant'
    1> with
    1> [
    1> T=AKS::CAksDataSet
    1> ]
    1>c:\users\édouard\documents\visual studio 2010\projects\readinexcel\aksvariant.h(255): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
    1>c:\users\édouard\documents\visual studio 2010\projects\readinexcel\aksvariant.h(255): error C2143: syntax error : missing ',' before '&'
    1>c:\program files\microsoft visual c++ 2010 express\vc\atlmfc\include\afx.h(24): fatal error C1189: #error : Building MFC application with /MD[d] (CRT dll version) requires MFC shared dll version. Please #define _AFXDLL or do not use /MD[d]
    1>
    1>Build FAILED.
    1>
    1>Time Elapsed 00:00:25.77
    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

  20. #40
    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
    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
    // fichier Aks.Excel.h
     
     #pragma once
     
    #include <atlcomtime.h>
    #include "AksVariant.h"
    #include "AksDataSet.h"
    #include "AksSafeArray.h"
    #include "AksComPtrT.h"
     
    #include "OfficeImport.h"
    #include "ExcelImport.h"
     
    #include "AksRange.h"
    #include "AksWorkSheet.h"
    #include "AksWorkSheets.h"
    #include "AksWorkBook.h"
    #include "AksWorkBooks.h"
    #include "AksExcelApp.h"
    Insére le fichier que j'ai mis en rouge dans Aks.Excel.h
    Ensuite remontre moi les nouvelles erreurs

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