Page 1 of 1

Default Format and Multiple Tabs

Posted: Wed Oct 22, 2014 3:11 pm
by jimbo1999
Hello,

I'm trying to upgrade our XLS library to XLSReadWriteII5 and have hit problems with the default formats. Previously (with .xls files) the default was Arial and size 10, but after the upgrade the default seems to be Calibri and size 11. I'm trying to prevent this change to avoid users complaining.

I've applied the following code shortly after creating the object:

Code: Select all

oXLS.CmdFormat.BeginEdit(nil);
oXLS.CmdFormat.Font.Name := 'Arial';
oXLS.CmdFormat.Font.Size := 10;
oXLS.CmdFormat.AddAsDefault('ExcelDef');
oXLS.DefaultFormat := oXLS.CmdFormat.Defaults.Find('ExcelDef');
This works fine for all text on the first tab, but once that tab's finished I add a new tab using oXLS.Add, but all text on the subsequent tabs revert back to Calibri size 11. I've tried reusing the code above after adding the new sheet, passing the new TXLSWorksheet to BeginEdit, calling AddAsDefault with a unique name, or simply trying to set the DefaultFormat using the format I added at creation time, but nothing seems to work.

Is there a line of code I'm missing somewhere so the new tabs use the defaults from the first?

Many thanks,
James

Re: Default Format and Multiple Tabs

Posted: Fri Oct 24, 2014 12:03 pm
by jimbo1999
OK I've got a bit further with this and now have a spreadsheet where the default font is working on subsequent tabs - almost.

I've modified the code so it reads as follows:

On create:

Code: Select all

oXLS.CmdFormat.BeginEdit(nil);
oXLS.CmdFormat.Font.Name := 'Arial';
oXLS.CmdFormat.Font.Size := 10;
FDefaultFormat := oXLS.CmdFormat.AddAsDefault('ExcelDef');
Then on create and every time I add a new tab:

Code: Select all

oXLS.DefaultFormat := FDefaultFormat;
What's strange is that this seems to work with "normal" text on subsequent tabs (i.e. cells with no explicit formatting) but as soon as I try to apply additional formatting in a function it reverts back to Calibri, even though we're explicitly setting the font name to Arial as follows (I'm calling this with an empty string so the Coalesce will fall back to Arial):

Code: Select all

procedure SetExcelFont (sFontName : string; nStartCol, nStartRow, nEndCol, nEndRow : integer);
begin
oXLS.CmdFormat.BeginEdit(curSheet);
oXLS.CmdFormat.Font.Name := Coalesce([sFontName, 'Arial']);
oXLS.CmdFormat.Apply(nStartCol, nStartRow, nEndCol, nEndRow);
end;
This one seems really strange as it seems the font name value is being ignored. Anyone any ideas what I'm doing wrong?

Thanks,
James

Re: Default Format and Multiple Tabs

Posted: Wed Oct 29, 2014 6:55 am
by larsa
Hello

Can you please provide a complete code sample?

Re: Default Format and Multiple Tabs

Posted: Thu Nov 06, 2014 10:05 am
by jimbo1999
Hi Lars,

Thanks for your offer to help, but I've finally figured this out - I was applying a background colour to the cell after the font set (I have separate functions for setting font, background colour etc.), and even though I wasn't explicitly setting the font name when setting the background colour, it must have been picking up the default Calibri. I've now adjusted the background colour function to set the font styling as appropriate and it works OK.

James