NativeExcel suite v1.x

AddPicture method

Creates a picture from an existing file or TBitmap object. Returns a TXLSPicture object that represents the new picture.

Syntax

function AddPicture(FileName: WideString): TXLSPicture;
function AddPicture(Bitmap: TBitmap; Transparent: boolean = flase): TXLSPicture;
function AddPicture(Bitmap: TBitmap; TransparentPoint: TPoint): TXLSPicture;
FileNameRequired WideString. The file from which the picture is to be created.
BitmapRequired TBitmap. TBitmap object from which the picture is to be created.
TransparentOptional Boolean. True to use color of point[0, 0] as transparent color; False - Transparent color is undefined. Default value is False
TransparentPointOptional TPoint. Specifies the point with transparent color.

Remarks

NativeExcel supports the following image types: BMP, JPEG, PNG, EMF, WMF. Pictures supported only for MS Excel 97 and later file format

Example

This example creates new picture on sheet one.
With Workbook.Sheets[1] do begin
  Cells[2, 2].Select; //the upper-left corner of the picture
  Shapes.AddPicture('image.jpg');
end;
This example creates new picture using TBitmap object.
Var Bitmap: TBitmap;
begin
  ...
  With Workbook.Sheets[1] do begin
    Cells[2, 2].Select; //the upper-left corner of the picture
    Bitmap := TBitmap.Create;
    Bitmap.LoadFromFile('image.bmp');
    with Shapes.AddPicture(Bitmap) do begin
      //speicify White color as transparent
      TransparentColor := rgb(255,255,255);  
    end
    Bitmap.Free;
  end;
  ...
end
This example creates new picture and specifies white color as transparent.
With Workbook.Sheets[1] do begin
  Cells[2, 2].Select; //the upper-left corner of the picture
  with Shapes.AddPicture('image.jpg') do begin
    TransparentColor := $FFFFFF;
  end;
end;
Copyright © NikaSoft 2004-2012