The Font Object (SAFont)
Use CreateFont to set a Font object. The Font object represents a font style that you can use when
creating a reusable Style object, or a single-cell Format. To define a font, first
set the CreateFont object, then assign values to any or all of its properties, for example,
Set myfont = xlw.CreateFont
myfont.name = "Arial"
myfont.size = 10
myfont.color = rgb(100,100,0)
Font Methods and Properties
| Font Methods and Properties |
| Bold |
When set to True, displays text in bold.
'--- Set Bold to True for the format of a single cell
ws.cells("A1").format.font.bold = true
'--- Set Bold to True for a reusable style object
Set mystyle = xlw.CreateStyle
mystyle.font.bold = true
Top |
| Charset* |
Sets or returns the character encoding set of a given cell's font. The
following example demonstrates setting cell B25's character set to the symbol set.
ws.cells("B25").format.font.charset = 2 '--- Symbol set
Top |
| Color |
Defines the font color for the format of a
single cell, or for a reusable Style object. Use RGB codes to assign
color values.
'--- Set Color to RGB 255 (red) for the format of a single cell
ws.cells("A1").format.font.color = 255
'--- Set Color to RGB 255 (red) for a reusable style object
Set mystyle = xlw.CreateStyle
mystyle.font.color = 255
Top |
| Italic |
When set to True, displays text in italic.
'--- Set Italic to True for the format of a single cell
ws.cells("A1").format.font.italic = true
'--- Set Italic to True for a reusable style object
Set mystyle = xlw.CreateStyle
mystyle.font.italic = true
Top |
| Name |
Use the Name property to assign a font (Arial, Courier, etc.)
to your format or style.
'--- Set the font to Times New Roman for the format of a single cell
ws.cells("A1").format.font.name = "Times New Roman"
'--- Set the font to Times New Roman for a reusable style object
Set mystyle = xlw.CreateStyle
mystyle.font.name = "Times New Roman"
Top |
| QueryFontDisp* |
Returns the name of the font displayed in
a specified cell.
'--- Display the font name assigned to the format of a single cell
ws.cells("B5").value = ws.cells("A5").format.font.QueryFontDisp
'--- Display the font name assigned to a reusable Style object
ws.cells("A14").value = mystyle.font.queryfontdisp
Top |
| Size |
Defines font size.
'--- Set font size to 8 pt. for the format of a single cell
ws.cells("A1").format.font.size = 8
'--- Set font size to 8 pt. for a reusable Style object
mystyle.font.size = 8
Top |
| Strikethrough* |
When set to True, displays text in
strikethrough format.
'--- Set Strikethrough to True for the format of a single cell
ws.cells("A1").format.font.strikethrough = true
'--- Set Strikethrough to True for a reusable style object
Set mystyle = xlw.CreateStyle
mystyle.font.strikethrough = true
Top |
| Subscript* |
When set to True, displays text in subscript format.
'--- Set Subscript to True for the format of a single cell
ws.cells("A1").format.font.subscript = true
'--- Set Subscript to True for a reusable style object
Set mystyle = xlw.CreateStyle
mystyle.font.subscript = true
Top |
| Superscript* |
When set to True, displays text in superscript format.
'--- Set Superscript to True for the format of a single cell
ws.cells("A1").format.font.superscript = true
'--- Set Superscript to True for a reusable style object
Set mystyle = xlw.CreateStyle
mystyle.font.superscript = true
Top |
| Underline* |
Sets or returns an underline style
for a specified cell, or for a style. Set Underline to any of the following
styles, using either the style's name or number.
| Style Name | Style Number | Comments |
| True | | Preserved for backward compatability.
Equivalent to saxlUnderline. |
| False | | Preserved for backward compatability.
Equivalent to saxlNoUnderline. |
| saxlUnderline | -1 | Equivalent to True. |
| saxlNoUnderline | 0 | Equivalent to False. |
| saxlSingleUnderline | 1 | For C++. Equivalent to True. |
| saxlDoubleUnderline | 2 | |
| saxlAccountingUnderline | 3 | |
| saxlDoubleAccountingUnderline | 4 | |
'--- Set Underline to saxlAccountingUnderline for the format of a single cell
ws.cells("A1").format.font.underline = saxlAccountingUnderline
'--- Set Underline to saxlDoubleUnderline for a reusable style object
Set mystyle = xlw.CreateStyle
mystyle.font.underline = saxlDoubleUnderline
Top |
| Weight* |
Use Weight to set a font to bold. The default value of Weight
is 400 (plain text). To display text in bold, set Weight to 700, as follows,
ws.cells("A38").format.font.weight = 700
Top |
| *This feature is not available in
ExcelWriterSE, ExcelWriterLE, or ExcelWriterFree. |
Copyright © 2003, SoftArtisans, Inc.