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
|
// fait avec le composant:
// XlsApp: TExcelApplication;
procedure TForm1.Button1Click(Sender: TObject);
var
XlsWk: _workbook;
XlsPage: _Worksheet;
ovWhat, ovAfter, ovLookIn, ovLookAt, ovSearchOrder, ovMatchCase, ovMatchByte: OleVariant;
vSearchDirection: XlSearchDirection;
rPlage: ExcelRange;
sText: string;
begin
XlsApp.Connect; // lance Excel
XlsApp.Visible[0] := true;
XlsWk := XlsApp.Workbooks.Open('F:\Prog\_Essai\Classeur1.XLS', False, False, EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam, 0); // ouverture XLS
XlsPage := XlsWk.Worksheets['Feuil1'] as _worksheet; // page 1
vSelection := XlsPage.Range['A1','D1'].EntireRow; // sélection 4 colonnes
ovWhat := 'Essai'; // le mot cherché
ovAfter := EmptyParam; // part ud début dse la sélection
ovLookIn := xlFormulas;
ovLookAt := xlPart; // recherche partielle
ovSearchOrder := xlByRows; // par colonne
vSearchDirection := xlNext;
ovMatchCase := False; // pas de respect casse
ovMatchByte := EmptyParam;
// lance la recherche
rPlage := XlsPage.Cells.Find(ovWhat, ovAfter, ovLookIn, ovLookAt, ovSearchOrder, vSearchDirection, ovMatchCase, ovMatchByte);
// récupère l'adresse dans la page
// property Address[RowAbsolute: OleVariant; ColumnAbsolute: OleVariant; ReferenceStyle: XlReferenceStyle; External: OleVariant; RelativeTo: OleVariant]: WideString readonly dispid 236;
sText := rPlage.Address[true, true, xlA1, false, false];
// format retour Address = 'R19C2' pour Row19Col2 si xlR1c1
// format retour Address = '$B$19' pour 'B19' si xA1
Edit4.Text := sText;
Edit2.Text := rPlage.Text; // contenu cellule trouvée
end; |
Partager