delphi에서 excel 형식 데이터베이스를 어떻게 동적 링크합니까

1889 단어 Delphi
     ,    XLS  (          ),       (     ,     COMBOBOX)
uses Excel97,(ExcelXP,)Excel2000 // ExcelXP
:
ExcelApplication1: TExcelApplication;
ExcelWorksheet1: TExcelWorksheet;
ExcelWorkbook1: TExcelWorkbook;
Edit1: TEdit;
OpenDialog1: TOpenDialog;
ComboBox1: TComboBox;
Button1: TButton;

procedure TMainF.Button1Click(Sender: TObject);// EXCEL
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(), ' !', ' ', mb_iconwarning);
abort;
end;

end;
end;

//
procedure TMainF.ComboBox1Select(Sender: TObject);
var
i: byte;
begin
with ADOQuery1 do //
try

Close;
sql.Clear;
Parameters.Clear;
ParamCheck := false;
sql.Add('SELECT * FROM [excel 8.0;database=' + Edit1.Text + '].[' + ComboBox1.Text + '$]');
open;

except
MessageBox(GetActiveWindow(), ' Excel !', ' ', MB_OK + mb_iconwarning);
end;
end;

좋은 웹페이지 즐겨찾기