Thema: Delphi Delphi 7 und MS Excel

Einzelnen Beitrag anzeigen

Benutzerbild von Jens Schumann
Jens Schumann

Registriert seit: 27. Apr 2003
Ort: Bad Honnef
1.644 Beiträge
 
Delphi 2009 Professional
 
#3

Re: Delphi 7 und MS Excel

  Alt 23. Aug 2005, 20:18
Hallo,
probiere es mal so:

Delphi-Quellcode:
procedure TForm1.CloseExcel;
begin
  ExcelWorksheet.Disconnect;
  ExcelWorkbook.Disconnect;
  ExcelApplication.AskToUpdateLinks[FLCID]:=True;
  ExcelApplication.Quit;
  ExcelApplication.Disconnect;
end;

procedure TForm1.OpenExcel;
begin
  FLCID:=GetUserDefaultLCID;
  ExcelApplication.Connect;
  ExcelApplication.Visible[FLCID] := True; // False wenn Excel unsichtbar sein soll
  ExcelApplication.UserControl := True; // False wenn Excel unsichtbar sein soll
  ExcelApplication.DisplayAlerts[FLCID]:=False;
  ExcelApplication.AskToUpdateLinks[FLCID]:=False;
end;

if OpenDialog.Execute then
        begin
          fileName:= OpenDialog.Filename;
          

          if fileName > 'then
            begin
              ExcelApplication.Workbooks.Open(fileName,EmptyParam, EmptyParam,
                                                 EmptyParam, EmptyParam, EmptyParam,
                                                 EmptyParam, EmptyParam, EmptyParam,
                                                 EmptyParam, EmptyParam, EmptyParam,
                                                 EmptyParam, EmptyParam, EmptyParam,FLCID);

          else
            ExcelApplication.Workbooks.Add(EmptyParam,FLCID);
  ExcelWorkbook.ConnectTo(ExcelApplication.ActiveWorkBook);
  ExcelWorksheet.ConnectTo(ExcelWorkbook.Sheets.Item['Tabelle1'] as _WorkSheet);
        end;
FLCID ist ein privates Feld des Formulars.
Mit OpenExcel Excel starten und mit CloseExcel Excel schließen und beenden.
I come from outer space to save the human race
  Mit Zitat antworten Zitat