1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
| Function Integrer_fichier(var h : THandle ; var Appli_OLE : Olevariant ; fichier_source : string ; panel : TPanel) : boolean;
var texte : string;
Attrs : integer;
t: DWORD;
begin
result := false;
Attrs := FileGetAttr(fichier_source); // récupère les attributs du fichier
if (Attrs and $00000001) <> 0 then FileSetAttr(fichier_source, Attrs - $00000001); // enlève la lecture seule
Appli_OLE.Workbooks.open(fichier_source,,false);
h := 0;
t:= GetTickCount;
texte := 'Microsoft Excel - ' + leftStr(extractfilename(fichier_source),length(extractfilename(fichier_source)) - 4);//extractfilename(fichier_source);
while (h = 0) and (GetTickCount - t < TimeOut) do
begin
h:= FindWindow(nil, PChar(texte));
Application.ProcessMessages;
end;
if h = 0 then
begin
h := 0;
t:= GetTickCount;
texte := 'Microsoft Excel - ' + extractfilename(fichier_source);
while (h = 0) and (GetTickCount - t < TimeOut) do
begin
h:= FindWindow(nil, PChar(texte));
Application.ProcessMessages;
end;
end;
if h <> 0 then
begin
// On change le parent de la fenêtre par notre panel (par exemple)
Windows.SetParent(h, panel.Handle);
FileSetAttr(fichier_source, $00000001); // Mise en lecture seule
Appli_OLE.visible:=true;
result := true;
end;
end; |
Partager