Fonts
Excel s Font object is much like Word s, with properties for Name, Size, Bold, Italic, and so forth. In Excel, fonts are controlled through the Font tab on the Format Cells dialog (see Figure 6). If we compare this dialog to Word s dialog box, we find that Excel has a subset of the Font properties that Word has. Fortunately, most of the properties that Excel s Font object has are found in Word, and are named similarly.
Figure 6
. The Excel Font tab on the Format Cells dialog. Excel provides a wide variety of font formatting features.To access the Font object, use the Range object s Font property (quite a few other objects, such as the various text objects on a chart, use the Font property, too). To set a range (in this example, the range is cell B2) to 14-point bold Times New Roman, use the following:
WITH oSheet.Range("B2").Font
.Name = "Times New Roman"
.Size = 14
.Bold = .T.
ENDWITH
Table 1
shows the font properties most commonly used in Excel. There are a few others available, though not nearly as many as there are in Word s Font object. Look in the Help file under "Font Object" for more properties.Table 1
. Font properties. The Font object controls the appearance of the font from the font face to its size, style, and much more. This table shows the more common properties. Check Help for additional settings. Property | Type | Description |
Name | Character | The name of the font. |
Size | Numeric | The size of the font in points. |
Color | RGB Color | The color of the font. |
Bold | Numeric or Logical | Indicates whether the text is bold. |
Italic | Numeric or Logical | Indicates whether the text is italic. |
Underline | Numeric | The type of underline. xlUnderlineStyleDouble -4119 xlUnderlineStyleDoubleAccounting 5 xlUnderlineStyleNone -4142 xlUnderlineStyleSingle 2 xlUnderlineStyleSingleAccounting 4
|
Superscript, Subscript | Numeric or Logical | Indicates whether the text is superscript or subscript, respectively. |
Excel has some properties that we list as "Numeric or Logical." These properties can be set with VFP s logical values of .T. and .F., or -1 (for true) and 0 (for false). However, when you query these properties, Excel returns a numeric value. So while you can turn on italics with oRange.Font.Italic = .T. or oRange.Font.Italic = -1, you must remember that it returns a numeric, as in IF oRange.Font.Italic = -1 ENDIF.
Copyright 2000 by Tamar E. Granor and Della Martin All Rights Reserved