Embedded-image support on the XLSX facade. Each image carries a top-left
anchor (Row/Col, 1-based), a size in EMU, the encoded bytes, and a
TXLSXImageFormat tag. The collection lives
on
TXLSXWorksheet.Images.
SaveAs writes the bytes into
xl/media/imageN.<ext> and
builds
xl/drawings/drawingN.xml +
_rels +
worksheet/content-type entries; Open parses everything back.
Declared in
lxHandleX.
TXLSXImageFormat declaration
type
TXLSXImageFormat = (
xlsxImagePng,
xlsxImageJpeg,
xlsxImageGif,
xlsxImageBmp);
The file extension and content-type registered in
[Content_Types].xml are picked from this enum on save.
TXLSXImage declaration
type
TXLSXImage = class
constructor Create;
procedure Assign(Source: TXLSXImage);
property Row: Integer;
property Col: Integer;
property WidthEMU: Integer;
property HeightEMU: Integer;
property Format: TXLSXImageFormat;
property Data: AnsiString;
end;
TXLSXImage members
| Row, Col |
1-based top-left anchor coordinates. The image is
anchored to the named cell and floats with it. |
| WidthEMU / HeightEMU |
Size in OOXML EMUs (English Metric Units).
XlsxEmuPerPixel = 9525, so 100 px square
translates to 100 * XlsxEmuPerPixel EMU. Default is
100×100 px. |
| Format |
Image format token. Determines the file extension
and content-type that SaveAs uses. |
| Data |
The raw encoded image bytes (already in the chosen
Format). Stored as AnsiString to keep the byte-stream
intact across the SaveAs round-trip. |
TXLSXImages declaration
type
TXLSXImages = class
function Add: TXLSXImage; overload;
function Add(Source: TXLSXImage): Integer; overload;
procedure Clear;
property Count: Integer;
property Items[Index: Integer]: TXLSXImage; default;
end;
Most callers use the worksheet shortcuts
AddImage(Row, Col, Data, Format) or
AddImageFromFile(Row, Col, FileName) rather than poking
at this collection directly.
Example
var
ws: TXLSXWorksheet;
begin
ws := Workbook.Sheets.Add('Demo');
ws.AddImageFromFile(1, 1, 'C:\Pictures\logo.png');
ws.Images[0].WidthEMU := 150 * XlsxEmuPerPixel;
ws.Images[0].HeightEMU := 75 * XlsxEmuPerPixel;
end;
See also