Activex OLE Delphi

procedure TForm1.Import1Click(Sender: TObject);
Var
ExcelApplication1 : TExcelApplication;
ExcelWorkBook1 : TExcelWorkBook;
ExcelWorkSheet1 : TExcelWorkSheet;
lcid : Integer;
aExcelFile : OleVariant;
aFile: String;
aCurrLine : integer;
aCurrColumn : integer;
begin
od.Title:= 'Shipmentinfo ';
if od.Execute then
begin
aFile:= od.FileName; //Dosya Ismı buraya
ExcelApplication1:=TExcelApplication.Create( self );
ExcelWorkBook1:=TExcelWorkBook.Create( self );
ExcelWorkSheet1:=TExcelWorkSheet.Create( self );
ExcelApplication1.Connect;
lcid := 1033;//Sisteminizde yuklu msoffice'in default LCID ülke kodu.
ExcelApplication1.Visible[ lcid ] := False;
aExcelFile:=aFile;
ExcelWorkBook1.ConnectTo(ExcelApplication1.Workbooks.Add(aExcelFile, lcid));
ExcelWorkSheet1.ConnectTo(ExcelWorkBook1.Worksheets[1] as _Worksheet);
if DataModule1.Shipmentinfo.Active then
DataModule1.Shipmentinfo.Close;
DataModule1.Shipmentinfo.Open;
aCurrLine:= 2;
while VarToStr(ExcelWorkSheet1.Cells.Item[ aCurrLine, 1 ].Value) <> '' do
begin
DataModule1.Shipmentinfo.insert;
DataModule1.shipmentinfo.FieldByName('Week').AsString:= ExcelWorkSheet1.Cells.Item[ aCurrLine, 1 ].Value; //Excel sheet 'deki alanların dbgrid karşılığı
DataModule1.shipmentinfo.FieldByName('Trailer').AsString:= ExcelWorkSheet1.Cells.Item[ aCurrLine, 2 ].Value;
DataModule1.shipmentinfo.FieldByName('Shipment').AsString:= ExcelWorkSheet1.Cells.Item[ aCurrLine, 3 ].Value;
DataModule1.shipmentinfo.FieldByName('Customer').AsString:= ExcelWorkSheet1.Cells.Item[ aCurrLine, 4 ].Value;
DataModule1.shipmentinfo.FieldByName('Name').AsString:= ExcelWorkSheet1.Cells.Item[ aCurrLine, 5 ].Value;
DataModule1.shipmentinfo.FieldByName('Zipcode').AsString:= ExcelWorkSheet1.Cells.Item[ aCurrLine, 6 ].Value;
DataModule1.shipmentinfo.FieldByName('City').AsString:= ExcelWorkSheet1.Cells.Item[ aCurrLine, 7 ].Value;
DataModule1.shipmentinfo.FieldByName('Colli').AsString:= ExcelWorkSheet1.Cells.Item[ aCurrLine, 9 ].Value;
DataModule1.shipmentinfo.FieldByName('Country').AsString:= ExcelWorkSheet1.Cells.Item[ aCurrLine, 8 ].Value;
DataModule1.shipmentinfo.FieldByName('Weight').AsString:= ExcelWorkSheet1.Cells.Item[ aCurrLine, 10 ].Value;
DataModule1.shipmentinfo.FieldByName('Unit').AsString:= ExcelWorkSheet1.Cells.Item[ aCurrLine, 11 ].Value;
DataModule1.Shipmentinfo.Post;
Self.Refresh;
inc( aCurrLine );
end;
ExcelWorkSheet1.Columns.Autofit;
ExcelApplication1.Visible[lcid]:=true;
ExcelWorksheet1.disconnect;
ExcelWorkbook1.disconnect;
ExcelApplication1.disconnect;
End;
End;