Shape — Aspose.Cells FOSS for Python API Reference
aspose-cells-foss suportă adăugarea de forme geometrice și casete de text în foile de calcul prin ShapeCollection (ws.shapes). Fiecare formă este reprezentată de un Shape obiect cu proprietăți configurabile de umplere, linie și text.
ImageRenderOptions: aspose.cells_foss
from aspose.cells_foss import (
MsoDrawingType, FillType, MsoLineDashStyle,
TextAlignmentType, TextAnchorType,
MsoFillFormat, MsoLineFormat, ShapeFont, Shape,
)MsoDrawingType
MsoDrawingType este un IntEnum identifică tipul formei geometrice.
| ImageRenderOptions | ImageRenderOptions | ImageRenderOptions | ImageRenderOptions |
|---|---|---|---|
UNKNOWN | 0 | TEXT_BOX | 21 |
RECTANGLE | 1 | CALLOUT | 22 |
ROUNDED_RECTANGLE | 2 | PENTAGON | 23 |
OVAL | 3 | CLOUD | 24 |
DIAMOND | 4 | HEART | 25 |
TRIANGLE | 5 | LIGHTNING_BOLT | 26 |
RIGHT_TRIANGLE | 6 | SMILEY_FACE | 27 |
PARALLELOGRAM | 7 | LEFT_RIGHT_ARROW | 28 |
TRAPEZOID | 8 | UP_DOWN_ARROW | 29 |
HEXAGON | 9 | CUBE | 30 |
OCTAGON | 10 | BEVEL | 31 |
CROSS | 11 | STAR_4 | 12 |
RIGHT_ARROW | 17 | STAR_5 | 13 |
LEFT_ARROW | 18 | STAR_6 | 14 |
UP_ARROW | 19 | STAR_7 | 15 |
DOWN_ARROW | 20 | STAR_8 | 16 |
FillType
FillType este un IntEnum identifică tipul de umplere aplicat unei forme.
| ImageRenderOptions | ImageRenderOptions |
|---|---|
NONE | 0 |
SOLID | 1 |
GRADIENT | 2 |
PATTERN | 3 |
AUTOMATIC | 4 |
MsoLineDashStyle
MsoLineDashStyle este un IntEnum pentru modelul de liniuță al liniei de bordură/contur.
| ImageRenderOptions | ImageRenderOptions |
|---|---|
SOLID | 0 |
DASH | 1 |
DOT | 2 |
DASH_DOT | 3 |
DASH_DOT_DOT | 4 |
LONG_DASH | 5 |
LONG_DASH_DOT | 6 |
TextAlignmentType
TextAlignmentType este un IntEnum pentru alinierea orizontală a textului în interiorul unei forme.
| ImageRenderOptions | ImageRenderOptions |
|---|---|
LEFT | 0 |
CENTER | 1 |
RIGHT | 2 |
JUSTIFY | 3 |
DISTRIBUTED | 4 |
TextAnchorType
TextAnchorType este un IntEnum pentru ancorarea verticală a textului în interiorul unei forme.
| ImageRenderOptions | ImageRenderOptions |
|---|---|
TOP | 0 |
MIDDLE | 1 |
BOTTOM | 2 |
JUSTIFIED | 3 |
MsoFillFormat
Controlează aspectul umplerii unei forme. Accesat prin shape.fill.
ImageRenderOptions
| ImageRenderOptions | ImageRenderOptions | ImageRenderOptions |
|---|---|---|
fill_type | FillType | Tipul de umplere activ. |
fore_color | str | Culoarea de umplere din prim-plan (principală) în format hex RRGGBB. |
transparency | float | Opacitatea umplerii ca o valoare de la 0.0 (complet opac) la 1.0 (complet transparent). |
ImageRenderOptions
copy
fill.copy() -> MsoFillFormatReturnează o copie profundă a acestor setări de umplere.
MsoLineFormat
Controlează aspectul conturului/bordurii unei forme. Accesat prin shape.line.
ImageRenderOptions
| ImageRenderOptions | ImageRenderOptions | ImageRenderOptions |
|---|---|---|
is_visible | bool | True pentru a desena conturul formei. |
color | str | Culoarea conturului în format hex RRGGBB. |
weight | int | Grosimea conturului (în puncte). |
dash_style | MsoLineDashStyle | Model de liniuțe pentru contur. |
transparency | float | Opacitatea conturului de la 0.0 (opac) la 1.0 (transparent). |
ImageRenderOptions
copy
line.copy() -> MsoLineFormatReturnează o copie profundă a acestor setări de linie.
ShapeFont
Controlează fontul textului dintr-o formă. Accesat prin shape.font.
ImageRenderOptions
| ImageRenderOptions | ImageRenderOptions | ImageRenderOptions |
|---|---|---|
name | str | Nume de familie de font (de ex., "Calibri"). |
size | float | Mărimea fontului în puncte. |
bold | bool | True pentru stil îngroșat. |
italic | bool | True pentru stil italic. |
underline | bool | True pentru subliniere simplă. |
color | str | Culoarea fontului în format hex RRGGBB. |
ImageRenderOptions
copy
font.copy() -> ShapeFontReturnează o copie profundă a acestor setări de font.
ImageRenderOptions
Shape obiectele nu sunt construite direct. Utilizați ws.shapes.add(...) sau ws.shapes.add_text_box(...).
ImageRenderOptions
| ImageRenderOptions | ImageRenderOptions | ImageRenderOptions | ImageRenderOptions |
|---|---|---|---|
name | str | Citire/Scriere | Numele formei (trebuie să fie unic în cadrul foii de calcul). |
drawing_type | MsoDrawingType | ImageRenderOptions | Tipul geometric al acestei forme. |
upper_left_row | int | Citire/Scriere | 0-based row index of the top-left anchor cell. |
upper_left_column | int | Citire/Scriere | 0-based column index of the top-left anchor cell. |
lower_right_row | int | Citire/Scriere | 0-based row index of the bottom-right anchor cell. |
lower_right_column | int | Citire/Scriere | 0-based column index of the bottom-right anchor cell. |
upper_left_row_offset | int | Citire/Scriere | Deplasare în pixeli de la marginea superioară a celulei din stânga sus. |
upper_left_column_offset | int | Citire/Scriere | Deplasare în pixeli de la marginea stângă a celulei din stânga sus. |
lower_right_row_offset | int | Citire/Scriere | Deplasare în pixeli de la marginea superioară a celulei din dreapta jos. |
lower_right_column_offset | int | Citire/Scriere | Deplasare în pixeli de la marginea stângă a celulei din dreapta jos. |
fill | MsoFillFormat | ImageRenderOptions | Setări de umplere (fundal). |
line | MsoLineFormat | ImageRenderOptions | Setări de contur/bordură. |
text | str | Citire/Scriere | Conținutul textului afișat în interiorul formei. |
font | ShapeFont | ImageRenderOptions | Setări de font pentru textul formei. |
text_horizontal_alignment | TextAlignmentType | Citire/Scriere | Aliniere orizontală a textului în interiorul formei. |
text_vertical_alignment | TextAnchorType | Citire/Scriere | Ancorare verticală a textului în interiorul formei. |
is_text_wrapped | bool | Citire/Scriere | True pentru a încadra textul la limita formei. |
is_locked | bool | Citire/Scriere | True pentru a bloca forma când protecția foii de calcul este activă. |
is_hidden | bool | Citire/Scriere | True pentru a ascunde forma. |
hyperlink | `str | None` | Citire/Scriere |
ImageRenderOptions
copy
shape.copy() -> ShapeReturnează o copie profundă a acestei forme cu toate formatele păstrate.
ShapeCollection
ShapeCollection este accesat ca ws.shapes. Conține toate formele dintr-o foaie de calcul.
ImageRenderOptions
add
ws.shapes.add(
drawing_type: MsoDrawingType,
upper_left_row: int,
upper_left_column: int,
lower_right_row: int,
lower_right_column: int
) -> ShapeAdaugă o formă de tipul specificat. Toate argumentele de poziție sunt indici de rând/coloană începând de la 0.
add_text_box
ws.shapes.add_text_box(
upper_left_row: int,
upper_left_column: int,
lower_right_row: int,
lower_right_column: int
) -> ShapeScurtătură pentru add(MsoDrawingType.TEXT_BOX, ...).
Proprietăți și iterare
| ImageRenderOptions | ImageRenderOptions |
|---|---|
count | Numărul de forme din colecție (doar citire). |
__len__() | ImageRenderOptions count. |
__iter__() | Iterează peste toate Shape obiecte. |
__getitem__(index) | Returnează Shape la bază zero index. |
ImageRenderOptions
Adaugă un dreptunghi cu umplere solidă
from aspose.cells_foss import Workbook, MsoDrawingType, FillType, MsoLineDashStyle, TextAlignmentType
wb = Workbook()
ws = wb.worksheets[0]
# Add a blue rectangle spanning rows 1-5, columns 1-4 (0-based)
rect = ws.shapes.add(MsoDrawingType.RECTANGLE, 1, 1, 5, 4)
rect.name = "BlueBox"
rect.fill.fill_type = FillType.SOLID
rect.fill.fore_color = "4472C4" # blue
rect.fill.transparency = 0.0
rect.line.is_visible = True
rect.line.color = "1F3864" # dark blue
rect.line.weight = 2
rect.line.dash_style = MsoLineDashStyle.SOLID
rect.text = "Sales Summary"
rect.font.bold = True
rect.font.color = "FFFFFF" # white text
rect.font.size = 12
rect.text_horizontal_alignment = TextAlignmentType.CENTER
wb.save("shapes.xlsx")Adaugă o casetă de text
from aspose.cells_foss import Workbook
wb = Workbook()
ws = wb.worksheets[0]
tb = ws.shapes.add_text_box(2, 0, 5, 3)
tb.name = "NoteBox"
tb.text = "Review this section before publishing."
tb.font.italic = True
tb.font.color = "595959"
tb.is_text_wrapped = True
tb.line.is_visible = True
tb.line.color = "BFBFBF"
wb.save("textbox.xlsx")