I am currently using a different tool than FlexCel, and we have issues. I would like to learn as quickly as possible whether the move to FlexCel will allow us to resolve these concerns.
//Images
fs := TFileStream.Create('imagename.png', fmOpenRead or fmShareDenyNone);
try
ImgProps := TImageProperties_Create();
ImgProps.Anchor := TClientAnchor.Create(TFlxAnchorType.MoveAndDontResize, 2, 0, 2, 0, 5, 204, 9, 416);
ImgProps.ShapeName := 'Picture 1';
xls.AddImage(fs, ImgProps);
finally
fs.Free;
end;
TClientAnchor.Create(TFlxAnchorType.MoveAndDontResize, 2, 0, 2, 0, 5, 204, 9, 416);
/// <summary>
/// Creates a new image based on the image size.
/// </summary>
/// <param name="aAnchorType">How the image behaves when copying/inserting cells.</param>
/// <param name="aRow1">Row where to insert the image.</param>
/// <param name="aCol1">Column where to insert the image.</param>
/// <param name="aPixDy1">Delta in pixels that the image is moved from aRow1.</param>
/// <param name="aPixDx1">Delta in pixels that the image is moved from aCol1.</param>
/// <param name="height">Height in pixels.</param>
/// <param name="width">Width in pixels.</param>
/// <param name="Workbook">ExcelFile with the workbook, used to calculate the cells.</param>
class function Create(const aAnchorType: TFlxAnchorType; const aRow1: Int32; const aPixDy1: Int32; const aCol1: Int32; const aPixDx1: Int32; const height: Int32; const width: Int32; const Workbook: IRowColSize): TClientAnchor; overload; static;
procedure CreateFile;
var
xls: TExcelFile;
fs: TFileStream;
ImgProps: IImageProperties;
img: TUIImage;
begin
xls := TXlsFile.Create(true);
xls.NewFile(1, TExcelFileFormat.v2010); //Create a new Excel file with 3 sheets.
//Set the names of the sheets
xls.ActiveSheet := 1;
//Images
fs := TFileStream.Create('r:\test.png', fmOpenRead or fmShareDenyNone);
try
img := TUIImage.FromStream(fs);
try
ImgProps := TImageProperties_Create();
ImgProps.Anchor := TClientAnchor.Create(TFlxAnchorType.MoveAndDontResize,
2, 0, 3, 0, Trunc(img.Height), Trunc(img.Width), xls);
ImgProps.ShapeName := 'Picture 1';
finally
img.Free;
end;
fs.Position := 0;
xls.AddImage(fs, ImgProps);
finally
fs.Free;
end;
xls.SetCellValue(ImgProps.Anchor.Row2 + 1, ImgProps.Anchor.Col2 + 1, 'Hello from FlexCel');
xls.Save('r:\test.xlsx');
end;
Adrian, thanks, that's a great load of information!
ImgProps.Anchor := TClientAnchor.Create(TFlxAnchorType.MoveAndDontResize,
2, 0, 3, 0, Trunc(img.Height), Trunc(img.Width), xls);
Wonderful! Thanks again!
When I try to use the example in Delphi Seattle I get an error:
: [dcc32 Error] ExportPDFxls.pas(128): E2251 Ambiguous overloaded call to 'TImageProperties_Create'
FMX.FlexCel.Core.pas(1370): Related method: function TImageProperties_Create: IImageProperties;
VCL.FlexCel.Core.pas(1375): Related method: function TImageProperties_Create: IImageProperties;
I copied following from APIMATE in my application
//Images
fs := TFileStream.Create('imagename.jpg', fmOpenRead or fmShareDenyNone);
try
ImgProps := TImageProperties_Create();
ImgProps.Anchor := TClientAnchor.Create(TFlxAnchorType.MoveAndDontResize, 1, 0, 1, 277, 2, 97, 3, 128);
ImgProps.ShapeName := 'Picture 1';
xls.AddImage(fs, ImgProps);
finally
fs.Free;
end;
The line ImgProps := TImageProperties_Create(); gives the error.
I do not know how to solve this.
Please help
Hi,
It seems like you are using both FMX.FlexCel.Core and VCL.FlexCel.Core.
You should use only one: If it is a VCL application use VCL.FlexCel.Core and remove all FMX.FlexCel.Core references. If it is a FireMonkey application, use only FMX.FlexCel.Core.
Note also that you need to use VCL.FlexCel.Core just once in your app. For most units (which might be used from Firemonkey or VCL apps) just use FlexCel.Core.
Then once in your VCL/FMX only code use VCL/FMX.FlexCel.Core. For the rest, use FlexCel.Core.
Thanks for quick reply. Yes indeed I had accidentally Flexcore double in my uses clause.