Page 1 of 1

EAccessViolation when changing FontColor for multiple cells

Posted: Thu Feb 28, 2013 9:10 am
by d3nton
Hi!

I got an EAccessViolation in function TXc12XF.GetFont when changing the FontColor for multiple cells (XLSReadWriteII 5.10.02).
I am not sure but it seems that this error only occurs if I am using the old xls format.

Sample code:
var
ExcelFile5 : TXLSReadWriteII5;
lindex :Integer;
begin
ExcelFile5 := TXLSReadWriteII5.Create(nil);
ExcelFile5.Version := Xc12Utils5.xvExcel97; <---- using old xls format
ExcelFile5.Filename := 'D:\output.xls';
for lIndex := 0 to 1000 do begin
ExcelFile5[0].AsString[0,lIndex] := 'test';
ExcelFile5[0].Cell[0,lindex].FontColor := $5050FF; <------- this results in an EAccessViolation
end;

ExcelFile5.Write;
end;

Any help would be appreciated.
Thank you.

Re: EAccessViolation when changing FontColor for multiple cells

Posted: Thu Feb 28, 2013 10:53 am
by larsa
Hello

Don't use the Cell object for formatting several cells. It's only usefull for just formatting a few cells, or read the format of cells.
Use CmdFormat instead. Example:

Code: Select all

  for i := 0 to 1000 do
    XLS[0].AsString[1,i] := 'Test';

  XLS.CmdFormat.BeginEdit(XLS[0]);
  XLS.CmdFormat.Font.Color.RGB := $5050FF;
  XLS.CmdFormat.Apply(1,0,1,1000);

Re: EAccessViolation when changing FontColor for multiple cells

Posted: Thu Mar 14, 2013 10:37 am
by d3nton
Hi!

Thank you! Works great.
Unfortunately I have a similar problem when trying to convert multiple cells into date format. I get the same EAccessViolation.
I know, I should not access the cells directly for formatting multiple cells but I don't find a function similar to the cmdformat which converts the cells into date format:

Sample
var
ExcelFile5 : TXLSReadWriteII5;
lindex :Integer;
begin
ExcelFile5 := TXLSReadWriteII5.Create(nil);
ExcelFile5.Version := Xc12Utils5.xvExcel97;
ExcelFile5.Filename := 'D:\output.xls';
for lIndex := 0 to 1000 do begin
ExcelFile5[0].AsDateTime[0,lindex] := date; <- EAccessViolation
end;

ExcelFile5.Write;
end.

Is there a function (similar to the cmdformat) which can be used for this?
Thank you.

Re: EAccessViolation when changing FontColor for multiple cells

Posted: Mon Mar 18, 2013 12:42 pm
by larsa
Hello

This is fixed in update 5.10.06

Re: EAccessViolation when changing FontColor for multiple cells

Posted: Tue Mar 19, 2013 8:02 am
by d3nton
Thank you.
The EAccessViolation issue seems to be fixed. But now I got a corrupted xls file with the code above.
Opening the created xls file in Excel results in the following message: Protected view - 'Office has detected a problem with the file. Editing it may harm your computer. Click more for details'.

Re: EAccessViolation when changing FontColor for multiple cells

Posted: Thu Mar 21, 2013 9:32 am
by larsa
Hello

FIxed in update 5.10.07