Font
- class Font
The font object can be accessed as an attribute of the range or shape object.
mysheet['A1'].fontmysheet.shapes[0].font
在 0.23.0 版本加入.
- property api: Any
Returns the native object (
pywin32orappscriptobj) of the engine being used.在 0.23.0 版本加入.
- property bold: bool | None
Returns or sets the bold property (boolean).
>>> sheet['A1'].font.bold = True >>> sheet['A1'].font.bold True
- Setter type:
bool
在 0.23.0 版本加入.
- property color: tuple[int, int, int] | None
Returns or sets the color property (tuple).
>>> sheet['A1'].font.color = (255, 0, 0) # or '#ff0000' >>> sheet['A1'].font.color (255, 0, 0)
- Setter type:
tuple[int, int, int] | str
在 0.23.0 版本加入.
- async get_bold()
Fetch the bold property on demand.
Noneif the range's cells don't all agree.Requires xlwings Lite.
- 返回类型:
bool | None
- async get_color()
Fetch the font color on demand, as an RGB tuple.
Noneif unset or if the range's cells don't all agree.Requires xlwings Lite.
- 返回类型:
tuple[int, int, int] | None
- async get_italic()
Fetch the italic property on demand.
Noneif the range's cells don't all agree.Requires xlwings Lite.
- 返回类型:
bool | None
- async get_name()
Fetch the font name on demand.
Noneif the range's cells don't all agree.Requires xlwings Lite.
- 返回类型:
str | None
- async get_size()
Fetch the font size on demand.
Noneif the range's cells don't all agree.Requires xlwings Lite.
- 返回类型:
float | None
- property italic: bool | None
Returns or sets the italic property (boolean).
>>> sheet['A1'].font.italic = True >>> sheet['A1'].font.italic True
- Setter type:
bool
在 0.23.0 版本加入.
- property name: str | None
Returns or sets the name of the font (str).
>>> sheet['A1'].font.name = 'Calibri' >>> sheet['A1'].font.name Calibri
- Setter type:
str
在 0.23.0 版本加入.
- set(*, bold=..., italic=..., size=..., color=..., name=...)
Sets one or more font attributes in one go.
Only the attributes you pass are written. All arguments are validated before anything is written.
- 参数:
bold (bool) -- See
Font.bold.italic (bool) -- See
Font.italic.size (float) -- A positive font size, see
Font.size.color (tuple[int, int, int] | str | int) -- An RGB tuple, a hex string or an Excel color integer, see
Font.color.name (str) -- See
Font.name.
示例
>>> sheet["A1:D1"].font.set(bold=True, size=14, color="#ff0000") >>> sheet.shapes[0].font.set(italic=True, name="Arial")
在 0.37.6 版本加入.