Skip to content
本页内容

Font (属性)

返回一个 Font 对象,该对象允许用户根据单元格的字体格式设置或返回搜索条件。

示例

python
#此示例设置搜索条件以识别包含红色字体的单元格,应用该条件创建一个单元格,找到该单元格,并通知用户
def test():
    # Set the search criteria for the font of the cell format.
    Application.FindFormat.Font.ColorIndex = 3

    # Set the color index of the font for cell A5 to red.
    Application.Range("A5").Font.ColorIndex = 3
    Application.Range("A5").Formula = "Red font"
    Application.Range("A1").Select()
    print("Cell A5 has red font")

    # Find the cells based on the search criteria.
    Application.Cells.Find("", ActiveCell, xlFormulas, xlPart, xlByRows, xlNext, False, None, True).Activate()
    print("ET has found this cell matching the search criteria.")
python
#此示例显示查找条件中单元格的字体和字号
def test():
    font = Application.FindFormat.Font
    print(f"字体为{font.Name},字号为{font.Size}")