Daha önce yazıp sattığım bir uygulamada bir exceldeki bir sutunda yer alan stok numaralarını alıp resimleri ilgili klasörde bulup ilgili excel dosyasına yerleştiriyordum. yerleştirme kısmını aşağıdaki kod ile gerçekleştirdim. Belki Faydası olur.
Not : Sadece bir kısmını aldığım için değişkenlere vs takılmayın. ama mantık aşağıdaki gibidir.
uses ComObj;
var
Excel_App,Resim_Obj: Variant ;
Resim,Dosya_Yolu,Dosya_Adi,
Dosya_jpg,Dosya_png,Dosya_jpeg,Dosya_bmp : String;
Aktif_Sayfa,Veri,Hucre : Variant;
cell, aLeft, aTop, aWidth, aHeight : Integer;
K_Satir,K_sutun,R_sutun : integer;
H_yukseklik, H_genislik : integer;
begin
Excel_App := CreateOleObject('Excel.Application');
Excel_App.Workbooks.Open(Form1.Excel_Dosya_Yolu.text);
// Hücre Seç
Excel_App.Cells[cell,R_sutun].Select;
Hucre := Excel_App.ActiveSheet;
Hucre.Cells[cell, R_sutun].ColumnWidth :=H_genislik;
Hucre.Cells[cell, R_sutun].RowHeight :=H_yukseklik;
// Resim Boyutu Ayarlanıyor
aLeft := Hucre.Cells[cell,R_sutun].Left + 2;
aTop := Hucre.Cells[cell,R_sutun].Top + 2;
aWidth := Hucre.Cells[cell,R_sutun+1].Left - Hucre.Cells[cell, R_sutun].Left - 4 ;
aHeight := Hucre.Cells[cell+1,R_sutun].Top - Hucre.Cells[cell, R_sutun].Top - 4;
Resim_Obj := Excel_App.ActiveSheet.Shapes.AddPicture(Resim,
False, // LinkToFile parametresi (dosya bağını kopardık...)
True , // SaveWithDocument parametresi (içerik excel dosyası ile kaydedilecek)
aLeft , // Left ( varsayılan sol offset )
aTop , // Top ( varsayılan tepe offset )
aWidth , // Width ( varsayılan genişlik )
aHeight); // Height (varsayılan yükseklik )
Resim_Obj.LockAspectRatio := msoFalse;
Resim_Obj.Placement := xlPortrait;
Excel_App.Visible:=true;
Excel_App := Unassigned;
end;