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);
} |
Partager