Style Class¶
numbers_parser
currently only supports paragraph styles and cell
styles. The following styles are supported:
font attributes: bold, italic, underline, strikethrough
font selection and size
text foreground color
horizontal and vertical alignment
cell background color
cell background images
cell indents (first line, left, right, and text inset)
Numbers conflates style attributes that can be stored in paragraph styles (the style menu in the text panel) with the settings that are available on the Style tab of the Text panel. Some attributes in Numbers are not applied to new cells when a style is applied.
To keep the API simple, numbers-parser
packs all styling into a single
Style
object. When a document is saved, the attributes not
stored in a paragraph style are applied to each cell that includes it.
Styles are read from cells using the Cell
property
style
and you can add new styles to a
Document
using add_style()
.
red_text = doc.add_style(
name="Red Text",
font_name="Lucida Grande",
font_color=RGB(230, 25, 25),
font_size=14.0,
bold=True,
italic=True,
alignment=Alignment("right", "top"),
)
table.write("B2", "Red", style=red_text)
table.set_cell_style("C2", red_text)
- class numbers_parser.Style[source]¶
A named document style that can be applied to cells.
- Parameters:
alignment (Alignment, optional, default: Alignment("auto", "top")) – Horizontal and vertical alignment of the cell
bg_color (RGB | List[RGB], optional, default: RGB(0, 0, 0)) – Background color or list of colors for gradients
bold (bool, optional, default: False) –
True
if the cell font is boldfont_color (RGB, optional, default: RGB(0, 0, 0)) – Font color)
font_size (float, optional, default: DEFAULT_FONT_SIZE) – Font size in points
font_name (str, optional, default: DEFAULT_FONT_SIZE) – Font name
italic (bool, optional, default: False) –
True
if the cell font is italicname (str, optional) – Style name
underline (bool, optional, default: False) – True if the) – cell font is underline
strikethrough (bool, optional, default: False) – True if) – the cell font is strikethrough
first_indent (float, optional, default: 0.0) – First line) – indent in points
left_indent (float, optional, default: 0.0) – Left indent in points
right_indent (float, optional, default: 0.0) – Right indent in points
text_inset (float, optional, default: DEFAULT_TEXT_INSET) – Text inset in points
text_wrap (str, optional, default: True) –
True
if text wrapping is enabled
- Raises:
TypeError: – If arguments do not match the specified type or for objects have invalid arguments
IndexError: – If an image filename already exists in document
- class numbers_parser.BackgroundImage[source]¶
A named document style that can be applied to cells.
fh = open("cats.png", mode="rb") image_data = fh.read() cats_bg = doc.add_style( name="Cats", bg_image=BackgroundImage(image_data, "cats.png") ) table.write(0, 0, "❤️ cats", style=cats_bg)
Currently only standard image files and not ‘advanced’ image fills are supported. Tiling and scaling is not reported back and cannot be changed when saving new cells.
- Parameters:
data (bytes) – Raw image data for a cell background image.
filename (str) – Path to the image file.
- property data: bytes¶
The background image as bytes for a cell, or None if no image.
- Type:
bytes
- property filename: str¶
The image filename for a cell, or None if no image.
- Type:
str