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,
[VBScript]
Set myFont = XlwApp.CreateFont()
myFont.Name = "Arial"
myFont.Size = 10
myFont.Color = RGB(0,0,255)
Font Methods and Properties
| Font Methods and Properties |
| Bold |
When set to True, displays text in bold.
Signature:
[VBScript]
Property Bold As Boolean (read/write)
[VBScript]
'--- 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.
Signature:
[VBScript]
Property CharSet As Integer (read/write)
The
following example demonstrates setting cell B25's character set to the symbol set.
[VBScript]
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.
Signature:
[VBScript]
Property Color As Long (read/write)
[VBScript]
'--- 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.
Signature:
[VBScript]
Property Italic As Boolean (read/write)
[VBScript]
'--- 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.
Signature:
[VBScript]
Property Name As String (read/write)
[VBScript]
'--- 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.
Signature:
[VBScript]
Function QueryFontDisp() As Object
[VBScript]
'--- 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.
Signature:
[VBScript]
Property Size As Long (read/write)
[VBScript]
'--- 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
Set mystyle = xlw.CreateStyle()
mystyle.font.size = 8
Top |
| Strikethrough* |
When set to True, displays text in
strikethrough format.
Signature:
[VBScript]
Property Strikethrough As Boolean (read/write)
[VBScript]
'--- 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.
Signature:
[VBScript]
Property Subscript As Boolean (read/write)
[VBScript]
'--- 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.
Signature:
[VBScript]
Property Superscript As Boolean (read/write)
[VBScript]
'--- 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.
Signature:
[VBScript]
Property Underline As SAXlUnderlineStyle (read/write)
| 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 | |
[VBScript]
'--- 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 |
| *This feature is not available in
ExcelWriterSE, ExcelWriterLE, or ExcelWriterFree. |
Copyright © 2005, SoftArtisans, Inc.