Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Win32/Win64 API (native code) (https://www.delphipraxis.net/17-win32-win64-api-native-code/)
-   -   Delphi Bilder aus Excel (https://www.delphipraxis.net/48316-bilder-aus-excel.html)

Masterof 23. Jun 2005 14:19


Bilder aus Excel
 
Hallo!

gibt es die Möglichkeit, Bild von Excel in mein Programm zu importieren?
Das Problem ist, dass die Bilder nicht in einer Zelle liegen sondern einfach ins Dokument
eingesetzt wurden.
Es handelt sich um einen Katalog mit mehreren hundert Bildern.

MfG Master

fylo 23. Jun 2005 14:39

Re: Bilder aus Excel
 
Hi

nimm doch lieber VBA für solche Probleme.

Masterof 23. Jun 2005 14:45

Re: Bilder aus Excel
 
Hallo!!

Kann meine Azswertungen nicht einfachmit VBA machen, da hängt noch mehr dran.

MfG Master

omata 23. Jun 2005 22:10

Re: Bilder aus Excel
 
Liste der Anhänge anzeigen (Anzahl: 1)
Moin,

habe mal ein Beispiel angehängt.

Vielleicht hilft es dir ja...

MfG
Thorsten

toms 23. Jun 2005 23:30

Re: Bilder aus Excel
 
Es gibt eine Moeglichkeit ohne Zwischenablage...

omata 24. Jun 2005 00:19

Re: Bilder aus Excel
 
Bin ich irgendwie blind?
Oder sollte das eine Frage werden?
Wenn nicht, wie?

PS: Toller Hinweis

toms 24. Jun 2005 06:15

Re: Bilder aus Excel
 
Zitat:

Zitat von omata
Bin ich irgendwie blind?
Oder sollte das eine Frage werden?
Wenn nicht, wie?

PS: Toller Hinweis

ok, hier mal ein Ansatz:


Delphi-Quellcode:
uses
  ActiveX, ComObj;

function GetRTFFormat(DataObject: IDataObject; var RTFFormat: TFormatEtc): Boolean;
var
  Formats: IEnumFORMATETC;
  TempFormat: TFormatEtc;
  pFormatName: PChar;
  Found: Boolean;
begin
  try
    OleCheck(DataObject.EnumFormatEtc(DATADIR_GET, Formats));
    Found := False;
    while (not Found) and (Formats.Next(1, TempFormat, nil) = S_OK) do
    begin
      pFormatName := AllocMem(255);
      GetClipBoardFormatName(TempFormat.cfFormat, pFormatName, 254);
      if (string(pFormatName) = 'Rich Text Format') then
      begin
        RTFFormat := TempFormat;
        Found := True;
      end;
      FreeMem(pFormatName);
    end;
    Result := Found;
  except
    Result := False;
  end;
end;

function ConvertToBMP(DataObject: IDataObject; Document: string): Boolean;
var
  FormatEtc: TFormatEtc;
  Medium: TStgMedium;
  Bitmap: TBitmap;
begin
//  OLEContainer.OLEObjectInterface.QueryInterface(IDataObject, DataObject);
  if DataObject <> nil then
  begin
    Result := True;
    FormatEtc.cfFormat := CF_BITMAP;
    FormatEtc.ptd := nil;
    FormatEtc.dwAspect := DVASPECT_CONTENT;
    FormatEtc.lIndex := -1;
    FormatEtc.tymed := TYMED_GDI;
    if DataObject.GetData(FormatEtc, Medium) >= 0 then
    begin
      try
        Bitmap := TBitmap.Create;
        Bitmap.LoadFromClipboardFormat(CF_BITMAP, Medium.hBitmap, 0);
        Bitmap.SaveToFile(Document);
        ReleaseStgMedium(Medium);
      finally
        Bitmap.Free;
      end;
    end;
  end;
end;


procedure TForm1.Button1Click(Sender: TObject);
var
  DataObject: IDataObject;
  RTFFormat: TFormatEtc;
  ReturnData: TStgMedium;
  Buffer: PChar;
  ExcelWB: _WorkBook;
  ExcelApp: _Application;
begin
  try
    GetActiveOleObject('Excel.Application').QueryInterface(_Application, ExcelApp);
  except
    ShowMessage('Error: Excel is not running');
    Exit;
  end;
  if (ExcelApp <> nil) then
  try
    ExcelWB := ExcelApp.ActiveWorkbook;
    ExcelWB.QueryInterface(IDataObject, DataObject);
    if ConvertToBMP(DataObject,'c:\test.bmp') then
    begin
      Caption := 'ok';
    end;
  except
      // Fehler aufgetreten...
  end;

end;

omata 24. Jun 2005 12:30

Re: Bilder aus Excel
 
ja, wunderbar.
Das ist doch mal ne Aussage...

Das mit der Zwischenablage war ein Schnellschuss, um das Problem zulösen.

Aber ich verstehe jetzt noch nicht so ganz...

wofür ist GetRTFFormat?

und wo ist die Schleife, die Frage war doch wie ich alle Bilder (z.B. 100 Stück) auslesen kann. Wie spreche ich bei deiner Variante die verschiedenen Bilder an?

Oder muss man jetzt noch deine und meine Variante zusammenführen?

Wie auch immer jetzt hat Masterof zwei Ansätze.

MfG
Thorsten

Die Muhkuh 24. Jun 2005 12:41

Re: Bilder aus Excel
 
hi,

toms hat geschrieben, dass das ein Ansatz ist.

Du musst jetzt halt den Code umschreiben, damit er das tut was du willst.


Alle Zeitangaben in WEZ +1. Es ist jetzt 04:14 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz