Einzelnen Beitrag anzeigen

omata

Registriert seit: 26. Aug 2004
Ort: Nebel auf Amrum
3.154 Beiträge
 
Delphi 7 Enterprise
 
#2

Re: vorhanden excel öffnen und daten aus formular übernehmen

  Alt 19. Jun 2006, 20:06
Versuche es doch mal so...

Delphi-Quellcode:
var Workbook, Filename, Excel: OleVariant;
    OpenDialog:TOpenDialog;
begin
  OpenDialog:=TOpenDialog.Create(Self);
  try
    OpenDialog.InitialDir:=ExtractFilePath(Application.ExeName);
    OpenDialog.Filter:='xls|*.xls';
    if OpenDialog.Execute then begin
      try
        Excel := CreateOleObject('Excel.Application');
        Excel.Visible := true; { für die testphase sinnvoll }

        Filename:=OpenDialog.FileName;
        Workbook:=Excel.Workbooks.Open(filename,
                                       emptyParam, emptyParam, emptyParam,
                                       emptyParam, emptyParam, emptyParam,
                                       emptyParam, emptyParam, emptyParam,
                                       emptyParam, emptyParam, emptyParam);
        // Excel.Workbooks.Add;
        Excel.ActiveWorkBook.Saved := True; // ... verhindert unliebsame Dialoge
        Excel.Cells[1, 1].Value := 'A';
        Excel.Cells[2, 1].Value := 'B';
        Excel.Cells[3, 1].Value := 'C';
        // Excel.Cells[4, 1].Value := DateTimePicker1.time;
        Excel.Cells[6, 1].Value := 'D';
      except
        ShowMessage('Excel konnte nicht gestartet werden !');
      end;
    end
  finally
    OpenDialog.free;
  end;
end;
MfG
Thorsten
  Mit Zitat antworten Zitat