Order and save right now!
20% off with the 729824315 dicscount code for Ultimate Pack and any another product for Delphi from Greatis Programming! |
⤷ Get data from excel file
This example shows, how to run Excel, open *.xls file and get data of this file into StringGrid component.Don't forget add ComObj in uses chapter.
procedure TForm1.Button1Click(Sender: TObject);
begin
Excel:=CreateOleObject('Excel.Application');
Excel.Visible:=True;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
Excel.Workbooks.Open(GetCurrentDir+'\book1.xls');
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
Excel.Workbooks.Close;
end;
procedure TForm1.Button4Click(Sender: TObject);
var
i, j: Integer;
begin
for i:=1 to 4 do
for j:=1 to 2 do
StringGrid1.Cells[j,i]:=
Excel.ActiveSheet.Cells[i,j].Value;
end;
-
More for developers