Help - Cell contents in Bold

This is probably such a newbie question but I can't figure it out and cannot find an explicit example anywhere which answers the question.
I've started using Flexcel and have successfully created my first Excel files from a Delphi app.
Now I want to try and be a little more clever but I'm getting stumped at my first attempt.
I simply want the content of some cells to be in bold text.
I've followed the tutorials.
I've got the format record:-

Fmt:=Xls.GetDefaultFormat;

I can change a cell's colour:-

Fmt.Font.Color:=clBlue;

I can set the font's size:-

Fmt.Font.Size20:=280;
//my understanding would be a 14pt font size

And following all I have seen I would set a font's style like this:-

Fmt.Font.Style:=TFlxFontStyles.Bold;

BUT this is causing a problem. I can't see what I'm doing wrong and can't figure it out from the help or the examples provided with FlexCel. I've spent all yesterday trying to see if the topic is listed here and trying to find it in the source. Do I need to declare anything else other than VCL.FlexCel.Core and FlexCel.XlsAdapter in my uses clause?
Thank you .

Hi,
TFlxFontStyles is a Delphi set (see Structured Types (Delphi) - RAD Studio )

That means that you can mix different font styles in your set, but you need to use brackets [ ] to specify the elements on the set. In this case, if you just want the font to be bold you would use:

 Fmt.Font.Style:=[TFlxFontStyles.Bold];

But if you wanted it to be bold and italic, you would use:

 Fmt.Font.Style:=[TFlxFontStyles.Bold, TFlxFontStyles.Italic];

You can also add Bold to the existing format of the cell, so if the cell was already italic, it will be italic and bold, but it it wasn't it will be just bold:

 Fmt.Font.Style:= Fmt.Font.Style + [TFlxFontStyles.Bold];

Or using Exclude/Include:

Include(Fmt.Font.Style, TFlxFontStyles.Bold);

As usual, remember that you can use APIMate for all this stuff, it makes it much simpler. So for example you can create a new Excel file, write "Hello" in cell A1, save the file and open it in APIMate (search for apimate in the start menu). It will show this code:

  //Set the cell values
  fmt := xls.GetCellVisibleFormatDef(1, 1);
  fmt.Font.Style := [TFlxFontStyles.Bold];
  xls.SetCellFormat(1, 1, xls.AddFormat(fmt));
  xls.SetCellValue(1, 1, 'Hello');

The beauty of APIMate is that you can use it for virtually anything you want to write in an Excel file. Want to add an autofilter? A table? Paint the cell with a gradient? APIMate can tell you how to do all of this.

Ahh, OK. I'd thought that if it was a set the actual style only would be included. Like so:-

Fmt.Font.Style:=TFlxFontStyles[Bold];

It didn't occur to me to include TFlxFontStyles in the brackets. That's probably why I was going around in circles.
Anyway, after your reply, I tried it with APIMate. Wow! Ok, I think I understand now. I think some of my forthcoming spreadsheet exports are going to be a little "over-engineered" for a while ....

Thank you for taking the time to reply.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.