Page 1 of 1

Default format example not working

Posted: Fri Mar 01, 2013 12:58 pm
by rjvanvliet
I try to implement the fastest method to format cells, but the example 'formatcells' shows only the format that is created al last. I moved 'F3' to the front and all the cells are not yellow anymore but red. So it donot listen to the if statements. That is a pitty because this method looks really good!!

Re: Default format example not working

Posted: Fri Mar 01, 2013 3:43 pm
by larsa
Hello

Can you please show me a complete code sample?

Re: Default format example not working

Posted: Fri Mar 01, 2013 5:38 pm
by rjvanvliet
It is just your example. I excepted to see 3 formats in the excelfile, but I only see the green color format[color=$10F040][/color]:

// Create first default format.
// The sheet parameter of BeginFormat is Nil, as it's not assigned to any
// particular woeksheet.
XLS.CmdFormat.BeginEdit(Nil);
XLS.CmdFormat.Fill.BackgroundColor.RGB := $7F7F10;
XLS.CmdFormat.Font.Name := 'Courier new';
XLS.CmdFormat.AddAsDefault('F1');

// Create second default format.
XLS.CmdFormat.BeginEdit(Nil);
XLS.CmdFormat.Fill.BackgroundColor.RGB := $FF1010;
XLS.CmdFormat.Font.Name := 'Ariel Black';
XLS.CmdFormat.AddAsDefault('F2');

// Create third default format.
XLS.CmdFormat.BeginEdit(Nil);
XLS.CmdFormat.Fill.BackgroundColor.RGB := $10F040;
XLS.CmdFormat.Font.Name := 'Times New Roman';
XLS.CmdFormat.Font.Style := [xfsBold,xfsItalic];
DefFmt_F3 := XLS.CmdFormat.AddAsDefault('F3');

// The default formats are in the XLS.CmdFormat.Defaults property.

for R := 2 to 100 do begin
if (R mod 4) = 0 then
// Assign format by name.
XLS.DefaultFormat := XLS.CmdFormat.Defaults.Find('F2')
else if (R mod 7) = 0 then
// Assign format by variable.
XLS.DefaultFormat := DefFmt_F3
else
// Assign format by index. We know that format 'F1' has index #0 as the
// list was empty.
XLS.DefaultFormat := XLS.CmdFormat.Defaults[0];
XLS[0].AsFloat[2,R] := 525;
end;

// Reset the default format.
XLS.DefaultFormat := Nil;

Re: Default format example not working

Posted: Sat Mar 02, 2013 4:29 pm
by larsa
Hello

This is fixed in 5.10.03

Re: Default format example not working

Posted: Sat Mar 02, 2013 5:31 pm
by rjvanvliet
Great!! :-D