AccessViolation in TXLSDrawing.InsertImage

Questions and answers on how to use XLSReadWriteII 5.
Post Reply
d3nton
Posts: 137
Joined: Thu Oct 25, 2012 9:48 am

AccessViolation in TXLSDrawing.InsertImage

Post by d3nton »

XlsReadWrite throws an Accessviolation in TXLSDrawing.InsertImage if AFilename: AxUCString leads to file which is not an image or if the file is an image but has a wrong extension (e.g. renamed .png to .txt)
Could you please handle this exception (maybe allow renamed images / check if image is assigned etc.. and/or throw a meaningfull exception.).
Thank you for your help.
larsa
Site Admin
Posts: 926
Joined: Mon Jun 27, 2005 9:30 pm

Re: AccessViolation in TXLSDrawing.InsertImage

Post by larsa »

Hello

Will fix this in the next update.
Lars Arvidsson, Axolot Data
d3nton
Posts: 137
Joined: Thu Oct 25, 2012 9:48 am

Re: AccessViolation in TXLSDrawing.InsertImage

Post by d3nton »

Hello!

Thank you for the fix.

In the current version I still receive a similar problem if I use the InsertImage function with a bmp image which should be included in a xls file:
The function call FGrManager.Images.LoadFromFile(AFilename); in the InsertImage function changes the bmp file to png and also changes the path of the file.
This leads to s EFOpenError exception in the next line:
DoInsertImage(Image,Round(Image.Width * AScale),Round(Image.Heigh * AScale),ACol,ARow,AColOffset,ARowOffset);
since the path with the renamed extension is not found.
larsa
Site Admin
Posts: 926
Joined: Mon Jun 27, 2005 9:30 pm

Re: AccessViolation in TXLSDrawing.InsertImage

Post by larsa »

Hello

I can't reproduce this

Which Delphi do you use?
Lars Arvidsson, Axolot Data
d3nton
Posts: 137
Joined: Thu Oct 25, 2012 9:48 am

Re: AccessViolation in TXLSDrawing.InsertImage

Post by d3nton »

Hi!

I use Delphi 10.1 Berlin.
Did you export to an xls file? It works for xlsx files but not for xls files.
larsa
Site Admin
Posts: 926
Joined: Mon Jun 27, 2005 9:30 pm

Re: AccessViolation in TXLSDrawing.InsertImage

Post by larsa »

Hello

Yes, I have tested with XLS files. It still works fine here.
Lars Arvidsson, Axolot Data
d3nton
Posts: 137
Joined: Thu Oct 25, 2012 9:48 am

Re: AccessViolation in TXLSDrawing.InsertImage

Post by d3nton »

You just need a bmp file (e.g. test.bmp) and use the example below in order to get an EAccessViolation or an error dialog 'Cannot open... text.png':

Code: Select all

var
  lExcelFile : TXLSReadWriteII5;

begin
   lExcelFile :=  TXLSReadWriteII5.Create(nil);
   lExcelFile.Filename := 'D:\testfile.xls';
   lExcelfile.Version := xvExcel97;
   lExcelFile.Add;
   lExcelFile[0].Drawing.InsertImage('D:\test.bmp', 1,1, 0, 0, 1);
   lExcelfile.Write;
   FreeAndNil(lExcelFile);
end;
larsa
Site Admin
Posts: 926
Joined: Mon Jun 27, 2005 9:30 pm

Re: AccessViolation in TXLSDrawing.InsertImage

Post by larsa »

Hello

Still no luck. Your code works fine.
Lars Arvidsson, Axolot Data
Post Reply