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
| Var
vMSExcel,
vXLClasseurs,
vXLClasIEP,
vXLClasTbl,
vFeuilIEP,
vFeuilTbl,
vRangeIEP,
vRangeTbl : variant;
CptT, CptP : Word;
Nouvel, K : Word;
NbCol : Byte;
CptTable : Byte;
PDeb, PFin : Byte;
Colonne : String[2];
LChamps : TStrings;
LChpsIE : TStrings;
ChampAbsent : Boolean;
AffTrouve : Boolean;
sChCh, Ch,
ChIEP,
ChTbl : String;
begin
LChamps := Tstringlist.Create;
LChamps.LoadFromFile(ChBasR + 'ListeChamps_E.TXT'); // Charge depuis le fichier
FBaseT := ChBasR + FTbl_E;
FBaseD := ChBasR + FIEP_E;
Memo2.Lines.Add('FBaseT: ' + FBaseT);
Memo2.Lines.Add('FBaseD: ' + FBaseD);
BtMaJTable_E.Enabled := true;
ChampAbsent := False;
AffTrouve := False;
vMSExcel := CreateOleObject('Excel.Application'); // Crée l'interface
vMSExcel.Visible := False; // Interface invisible
vMSExcel.DisplayAlerts := False ; // message d'alerte en route
try
vXLClasseurs := vMSExcel.Workbooks;
// BASE - BASE - BASE - BASE - BASE - BASE - BASE - BASE - BASE - BASE - BASE -
vXLClasTbl := vXLClasseurs.Open(FBaseT,unassigned,True); // IEP ReadOnly à True
vFeuilTbl := vXLClasTbl.WorkSheets[1];
vFeuilTbl.UsedRange.Select; // La plage de cellules utilisées est sélectionnée Memo2.Lines.Add('Feuille de Table_x sélectionnée');
vFeuilTbl.UsedRange.Sort(vFeuilTbl.Range['A1','A1'], xlDescending,
EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam,
xlGuess, 1, False, xlTopToBottom, EmptyParam); // La plage sélectionnée est triée
Memo2.Lines.Add('plage de Table_x sélectionnée est triée');
NbTLigT := vFeuilTbl.UsedRange.Rows.count; // Nombre de lignes utilisées dans la table Nouvel := NbTLigT + 1; // 1ère ligne disponible
Memo2.Lines.Add('Nombre de lignes utilisées dans la table Table_x : ' + IntToStr(NbTLigT));
vRangeTbl := vFeuilTbl.Range['A1', 'U' + IntToStr(NbTLigT+1500)].Value;
Memo2.Lines.Add('vRangeTbl: A1-U' + IntToStr(NbTLigT));
Finally
vXLClasTbl.Close; // vXLWorkbook.Close(vSaveChanges, aFileName);
VarClear(vXLClasTbl); // Variant effacé
VarClear(vFeuilTbl); // Variant effacé |
Partager