AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Sprachen und Entwicklungsumgebungen Sonstige Fragen zu Delphi Delphi Ist Excel schon gestartet? Wie Excel offen lassen?
Thema durchsuchen
Ansicht
Themen-Optionen

Ist Excel schon gestartet? Wie Excel offen lassen?

Ein Thema von diver03 · begonnen am 8. Dez 2008 · letzter Beitrag vom 10. Dez 2008
 
diver03

Registriert seit: 11. Dez 2007
24 Beiträge
 
Turbo Delphi für Win32
 
#6

Re: Ist Excel schon gestartet? Wie Excel offen lassen?

  Alt 9. Dez 2008, 12:00
So, jetzt hab ichs.

Delphi-Quellcode:
procedure ExcelMaschDatLesen();
  var sValue,filename:String;
      OleX : OleVariant;
      Zelle: String;
      excel : OleVariant;
      ExcelLaeuft : Boolean;
begin

....

  flcid := GetUserDefaultLCID;
  filename:=Form_Hauptformular.OpenDialog1.FileName;
  with Form_Hauptformular do
  begin
//
// prüfen ob Excel bereits läuft
//
  try
     excel := GetActiveOleObject('Excel.Application');
     ExcelLaeuft := TRUE;
     ShowMessage('excel läuft');
  except
     excel := CreateOleObject('Excel.Application');
     ExcelLaeuft := FALSE;
     ShowMessage('excel wurde gestartet');
     ExcelApplication1.Connect; // Wenn Excel noch nicht läuft, dann starten

  end;
//
// Excel Datei öffnen
//
    ExcelApplication1.Visible[flcid]:= TRUE;
    ExcelApplication1.UserControl := FALSE;
    ExcelWorkbook1.ConnectTo(ExcelApplication1.Workbooks.Open(filename,
                             emptyParam, //UpdateLinks: OleVariant
                             TRUE, //ReadOnly: OleVariant
                             emptyParam, //Format: OleVariant
                             emptyParam, //Password: OleVariant
                             emptyParam, //WriteResPassword: OleVariant
                             emptyParam, //IgnoreReadOnlyRecommended: OleVariant
                             emptyParam, //Orign: OleVariant
                             emptyParam, //Delimiter: OleVariant
                             emptyParam, //Editable: OleVariant
                             emptyParam, //Notify: OleVariant
                             emptyParam, //Converter: OleVariant
                             emptyParam, //AddToMru: OleVariant
                             emptyParam, //Local: OleVariant
                             emptyParam, //CorruptLoad: OleVariant
                             flcid));
    ExcelWorksheet1.ConnectTo(ExcelWorkbook1.Sheets.Item[1] as ExcelWorkSheet);
      Zelle := 'H1';
      sValue:=ExcelWorksheet1.Range[Zelle,Zelle].Value[OleX];
    MDaten.Form_MDaten.EditHandelsbezeichnungBl.Text := sValue;

.... // Werte einlesen

    ExcelApplication1.DisplayAlerts[flcid] := FALSE;
    ExcelWorksheet1.Disconnect;
    ExcelApplication1.ActiveWorkBook.Close(FALSE, emptyParam, emptyParam, flcid); // Workbook schließen
    if ExcelLaeuft = FALSE then
    begin
      ExcelApplication1.quit; // Wenn Excel gestartet wurde, dann schließen
      ExcelApplication1.Disconnect;
    end;
  end;
  Application.BringToFront; // eigenem Delphiprogramm wieder den Focus geben und nach vorne bringen
end;
Der Befehl Application.BringToFront; war das, was mir noch gefehlt hatte.

Vielen Dank für eure Hilfestellung.

Gruß
Jens
  Mit Zitat antworten Zitat
 


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 11:20 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz