Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Sonstige Fragen zu Delphi (https://www.delphipraxis.net/19-sonstige-fragen-zu-delphi/)
-   -   Delphi Excel offen und gesuchtes Workbook offen???? (https://www.delphipraxis.net/33671-excel-offen-und-gesuchtes-workbook-offen.html)

hoef 10. Nov 2004 23:05


Excel offen und gesuchtes Workbook offen????
 
Hallo, ich suche eine Möglichkeit wie ich in Delphi6 prüfen kann ob Excel schon läuft und besonders ob das gesuchte Workbook schon aktiv ist. Wäre toll, falls mir jemand helfen könnte :oops:

TheMiller 11. Nov 2004 00:01

Re: Excel offen und gesuchtes Workbook offen????
 
Hi,

ob Excel läuft, also, offen ist ;-), kann du mit dieser Funktion prüfen:

Delphi-Quellcode:
function ExeFileIsRunning(ExeFile: string): boolean;
var
  H:word;
begin
  H := CreateFile(PChar(ExeFile),
                  GENERIC_READ,
                  0,
                  nil,
                  OPEN_EXISTING,
                  0,
                  0);
  Result := (H >= 65535);
  CloseHandle(H);
end;
Ich hoffe, ich konnte dir ein bissl helfen!
Zu den Workbooks, schau doch mal in die Kategorie "Server" in Delphi und ab siehst du einige Excel-Server. Doch passe auf. Wenn du diese verwendest, muss der PC, auf dem dein Prog ausgeführt wird, mit der Excel-Version übereinstimmen, für die auch die verwendete Server-Komponente ist.

Bye
DJ-SPM

hoef 11. Nov 2004 15:10

Re: Excel offen und gesuchtes Workbook offen????
 
Danke, dank den Code-Library hab ich noch ne andere Möglichkeit gefund. Bleibt aber immer noch das Problem mit dem offenen Workbook. Aber hier werd ich deinen Rat aufjedenfall befolgen.

stonimahoni 13. Dez 2004 13:59

Re: Excel offen und gesuchtes Workbook offen????
 
hi

welche möglichkeit hast du denn noch gefunden ?
weil ich dasselbe in meinem programm abfragen möchte und such ne elegante lösung :)


thx 4 help

mfg

stoni

hoef 14. Dez 2004 19:49

Re: Excel offen und gesuchtes Workbook offen????
 
hi, ich habs jetzt wie folgt gelöst:

function TFrorm1.IsProgActive(sClassName: String): Boolean;
var
ClassID: TCLSID;
Unknown: IUnknown;
begin
try
ClassID := ProgIDToClassID(sClassName);
Result := GetActiveObject(ClassID, nil, Unknown) = S_OK;
except
Result := False;
end;
end;

procedure TForm1.Butto1Click(Sender: TObject);
const
xlCellTypeLastCell = $0000000B;
var
WorkAkt,AppAkt:Boolean;
MessPfad: String;
begin

Messpfad:='C:/2004_09_28_Messdaten.xls';

try
AppAkt:=false;
WorkAkt:=true;
try
//Abfrage ob Excel aktiv, dann
if IsProgActive('Excel.Application') then begin

TExcelApplication.ConnectKind := ckNewInstance instead of ckRunningOrNew;
AppAkt:=true;
ExcelApplication1 := TExcelapplication.Create(nil);
ExcelApplication1.ConnectKind := ckRunningOrNew;
ExcelApplication1.Connect;
ExcelApplication1.Visible[GetUserDefaultLCID]:=true;
ExcelApplication1.UserControl:=True;

//Falls Excel aktiv, auch mein Workbook???
if Messpfad <> ExcelApplication1.ActiveWorkbook.Path[GetUserDefaultLCID]+'\'+ExcelApplication1.ActiveWorkbook.Name
then begin
ExcelApplication1.Workbooks.Open
(Pfad,False,False,EmptyParam,'',False,False,EmptyP aram,EmptyParam,false,false,EmptyParam,false,0);
WorkAkt:=false;
end;

ExcelWorkbook1.ConnectTo(ExcelApplication1.ActiveW orkBook);

end
else begin

//Wenn nicht offen, dann aktiviere Excel und standartweg einleiten
WorkAkt:=false;
ExcelApplication1 := TExcelapplication.Create(nil);
ExcelApplication1.ConnectKind := ckRunningOrNew;
ExcelApplication1.Connect;
ExcelApplication1.Visible[GetUserDefaultLCID]:=true;
ExcelApplication1.UserControl:=True;
ExcelApplication1.Workbooks.Open(Pfad,False,False, EmptyParam,'',False,False,EmptyParam,EmptyParam,fa lse,false,EmptyParam,false,0);

// Workbook verbinden
ExcelWorkbook1.ConnectTo(ExcelApplication1.ActiveW orkBook);
end;

// Woorksheet verbinden und aktivieren
ExcelWorksheet1.ConnectTo(ExcelWorkbook1.Sheets.It em['Peltier'] as _Worksheet);
ExcelWorksheet1.Activate;

//Und jetzt Workbook und Worksheet auslesen...

Ich hoff ich kann damit etwas helfen. :idea:

Gruß

Daniel

P.S.: Falls noch jemand einen besseren Weg weiß, ich bin immer offen...


Alle Zeitangaben in WEZ +1. Es ist jetzt 15:28 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