How to apply a created font format to a cell?

Questions and answers on how to use XLSReadWriteII 3/4/5.
Post Reply
NickS
Posts: 5
Joined: Fri Apr 25, 2008 6:32 pm

How to apply a created font format to a cell?

Post 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.
larsa
Site Admin
Posts: 926
Joined: Mon Jun 27, 2005 9:30 pm

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

Post by larsa »

Hello

Example: XLS.Sheets[0].Cell[0,0].AssignFont(MyTFont);
Lars Arvidsson, Axolot Data
NickS
Posts: 5
Joined: Fri Apr 25, 2008 6:32 pm

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

Post 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!
larsa
Site Admin
Posts: 926
Joined: Mon Jun 27, 2005 9:30 pm

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

Post 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.
Lars Arvidsson, Axolot Data
Post Reply