Page 1 of 1

How to apply a created font format to a cell?

Posted: Mon May 17, 2010 5:29 pm
by NickS
Since we've upgraded from XLS2 to XLS4, a lot of code syntax was "broken" by the upgrade because of so many changes. I'm very surprised no backwards compatibility!

Anyways, with XLS2, you can create a new font, assign it an index and then output your string using that newly created font as such:

with ReportSheet.Formats.Add do begin
ReportSheet.Fonts[FontIndex].Name := 'Arial';
ReportSheet.Fonts[FontIndex].Style := [xfsBold];
// Save Format index
FI := Index;
end;

// Use correct format index
ReportSheet.Sheets[0].WriteString(0,AdminRow,FI,'Full Match');

This doesn't work at all in XLS4 when you want to do the output WriteString. I can't figure for the life of me to get this to work in XLS4.

Re: How to apply a created font format to a cell?

Posted: Tue May 18, 2010 9:08 am
by larsa
Hello

Example: XLS.Sheets[0].Cell[0,0].AssignFont(MyTFont);

Re: How to apply a created font format to a cell?

Posted: Tue May 18, 2010 2:37 pm
by NickS
Thanks Lars!

Again, in keeping with my XLS2 version program code, I would always create the XLS.Font.Add first and then XLS.Formats.Add and create an integer value to keep track of which Formats used which Font, like so:

with XLS.Formats.Add do
begin
FontIndex := 6;
HorizAlignment := chaCenter;
end;

And then FontIndex 6 ties back to a XLS.Font.Add that say was Arial and bold.

With your example in your reply above for the Fonts works great, but now I'm trying to figure out the Formats and how to tie them back to use the newly created Fonts.

Thanks again!

Re: How to apply a created font format to a cell?

Posted: Mon May 31, 2010 12:30 pm
by larsa
Hello

Don't use FontIndex (or FormatIndex) properties. These are only for internal use, as they might change due to optimization when formats/fonts are added or deleted.