Generally two-step, first determine the XLS file (with open dialog can be implemented), and then find the corresponding page (make a loop, and then write a ComboBox)
Uses EXCEL97, (EXCELXP,) Excel2000//Note Order EXCELXP Auto Plus
To add a control:
Excelapplication1:texcelapplication;
Excelworksheet1:texcelworksheet;
Excelworkbook1:texcelworkbook;
Edit1:tedit;
Opendialog1:topendialog;
Combobox1:tcombobox;
Button1:tbutton;
Procedure Tmainf.button1click (Sender:tobject);//Open Excel file
Var
I:integer;
Begin
If Opendialog1.execute Then
Begin
Edit1.text: = Opendialog1.filename;
Try
Excelworkbook1.connectto (ExcelApplication1.Workbooks.open (edit1.text, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0));
Excelworksheet1.connectto (Excelworkbook1.activesheet as _worksheet);
Combobox1.clear;
For I: = 1 to ExcelWorkbook1.Worksheets.Count do
Begin
COMBOBOX1.ITEMS.ADD ((Excelworkbook1.worksheets.item[i] as _worksheet). Name);
End
Excelapplication1.quit;
Excelworksheet1.disconnect;
Excelworkbook1.disconnect;
Excelapplication1.disconnect;
Except
MessageBox (GetActiveWindow (), ' Operation failed! ', ' warning ', mb_iconwarning);
Abort
End
End
End
Select the appropriate page name and open
Procedure Tmainf.combobox1select (Sender:tobject);
Var
I:byte;
Begin
With ADOQuery1 do//depending on your data connection control
Try
Close;
Sql. Clear;
Parameters.clear;
Paramcheck: = false;
Sql. ADD (' SELECT * from [Excel 8.0;database= ' + edit1.text + '].[' + Combobox1.text + ' $] ');
Open
Except
MessageBox (GetActiveWindow (), ' Open Excel File page name failed! ', ' warning ', MB_OK + mb_iconwarning);
End
End