Shape
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.
| Name | Type | Access | Description |
|---|---|---|---|
upper_left_row | `` | Read/Write | Gets or sets the upper left row. |
upper_left_column | `` | Read/Write | Gets or sets the upper left column. |
lower_right_row | `` | Read/Write | Gets or sets the lower right row. |
lower_right_column | `` | Read/Write | Gets or sets the lower right column. |
upper_left_row_offset | `` | Read/Write | Gets or sets the upper left row offset. |
upper_left_column_offset | `` | Read/Write | Gets or sets the upper left column offset. |
lower_right_row_offset | `` | Read/Write | Gets or sets the lower right row offset. |
lower_right_column_offset | `` | Read/Write | Gets or sets the lower right column offset. |
name | `` | Read | Gets the name. |
drawing_type | `` | Read | Gets the drawing type. |
fill | `` | Read | Gets the fill. |
line | `` | Read | Gets the line. |
text | `` | Read | Gets the text. |
font | `` | Read | Gets the font. |
text_horizontal_alignment | `` | Read | Gets the text horizontal alignment. |
text_vertical_alignment | `` | Read | Gets the text vertical alignment. |
is_text_wrapped | `` | Read | Gets the is text wrapped. |
is_locked | `` | Read | Gets the is locked. |
is_hidden | `` | Read | Gets the is hidden. |
placement | `` | Read | Gets the placement. |
hyperlink | `` | Read | Gets the hyperlink. |
FillType
FillType este un IntEnum identifică tipul de umplere aplicat unei forme.
| Signature | Description |
|---|---|
__init__(drawing_type, upper_left_row, upper_left_column, lower_right_row, lower_right_column) | |
copy() | Creates a duplicate of the shape object |
MsoLineDashStyle
MsoLineDashStyle este un IntEnum pentru modelul de liniuță al liniei de bordură/contur.
TextAlignmentType
TextAlignmentType este un IntEnum pentru alinierea orizontală a textului în interiorul unei forme.
TextAnchorType
TextAnchorType este un IntEnum pentru ancorarea verticală a textului în interiorul unei forme.
MsoFillFormat
Controlează aspectul umplerii unei forme. Accesat prin shape.fill.
ImageRenderOptions
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
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
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
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
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")