Shape — Aspose.Cells FOSS for Python API Reference
aspose-cells-foss admite la incorporación de formas geométricas y cuadros de texto a las hojas de cálculo a través de ShapeCollection (ws.shapes). Cada forma está representada por un Shape objeto con propiedades configurables de relleno, línea y texto.
ColladaSaveOptions: aspose.cells_foss
from aspose.cells_foss import (
MsoDrawingType, FillType, MsoLineDashStyle,
TextAlignmentType, TextAnchorType,
MsoFillFormat, MsoLineFormat, ShapeFont, Shape,
)MsoDrawingType
MsoDrawingType es un IntEnum que identifica el tipo de forma geométrica.
| ColladaSaveOptions | ColladaSaveOptions | ColladaSaveOptions | ColladaSaveOptions |
|---|---|---|---|
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 es un IntEnum que identifica el tipo de relleno aplicado a una forma.
| ColladaSaveOptions | ColladaSaveOptions |
|---|---|
NONE | 0 |
SOLID | 1 |
GRADIENT | 2 |
PATTERN | 3 |
AUTOMATIC | 4 |
MsoLineDashStyle
MsoLineDashStyle es un IntEnum para el patrón de guiones de la línea del borde/contorno.
| ColladaSaveOptions | ColladaSaveOptions |
|---|---|
SOLID | 0 |
DASH | 1 |
DOT | 2 |
DASH_DOT | 3 |
DASH_DOT_DOT | 4 |
LONG_DASH | 5 |
LONG_DASH_DOT | 6 |
TextAlignmentType
TextAlignmentType es un IntEnum para la alineación horizontal del texto dentro de una forma.
| ColladaSaveOptions | ColladaSaveOptions |
|---|---|
LEFT | 0 |
CENTER | 1 |
RIGHT | 2 |
JUSTIFY | 3 |
DISTRIBUTED | 4 |
TextAnchorType
TextAnchorType es un IntEnum para anclaje vertical de texto dentro de una forma.
| ColladaSaveOptions | ColladaSaveOptions |
|---|---|
TOP | 0 |
MIDDLE | 1 |
BOTTOM | 2 |
JUSTIFIED | 3 |
MsoFillFormat
Controla la apariencia de relleno de una forma. Accedido a través de shape.fill.
ColladaSaveOptions
| ColladaSaveOptions | ColladaSaveOptions | ColladaSaveOptions |
|---|---|---|
fill_type | FillType | El tipo de relleno activo. |
fore_color | str | Color de relleno de primer plano (principal) como RRGGBB hex. |
transparency | float | Opacidad del relleno como un valor de 0.0 (totalmente opaco) a 1.0 (totalmente transparente). |
ColladaSaveOptions
copy
fill.copy() -> MsoFillFormatDevuelve una copia profunda de estos ajustes de relleno.
MsoLineFormat
Controla la apariencia del contorno/borde de una forma. Accedido a través de shape.line.
ColladaSaveOptions
| ColladaSaveOptions | ColladaSaveOptions | ColladaSaveOptions |
|---|---|---|
is_visible | bool | True para dibujar el contorno de la forma. |
color | str | Color del contorno como RRGGBB hex. |
weight | int | Peso del contorno (grosor) en puntos. |
dash_style | MsoLineDashStyle | Patrón de guiones para el contorno. |
transparency | float | Opacidad del contorno desde 0.0 (opaco) a 1.0 (transparente). |
ColladaSaveOptions
copy
line.copy() -> MsoLineFormatDevuelve una copia profunda de estos ajustes de línea.
ShapeFont
Controla la fuente del texto dentro de una forma. Se accede a través de shape.font.
ColladaSaveOptions
| ColladaSaveOptions | ColladaSaveOptions | ColladaSaveOptions |
|---|---|---|
name | str | Nombre de la familia tipográfica (p. ej., "Calibri"). |
size | float | Tamaño de fuente en puntos. |
bold | bool | True para peso negrita. |
italic | bool | True para estilo cursiva. |
underline | bool | True para subrayado simple. |
color | str | Color de fuente como hexadecimal RRGGBB. |
ColladaSaveOptions
copy
font.copy() -> ShapeFontDevuelve una copia profunda de estos ajustes de fuente.
ColladaSaveOptions
Shape Los objetos no se construyen directamente. Use ws.shapes.add(...) o ws.shapes.add_text_box(...).
ColladaSaveOptions
| ColladaSaveOptions | ColladaSaveOptions | ColladaSaveOptions | ColladaSaveOptions |
|---|---|---|---|
name | str | Lectura/Escritura | Nombre de la forma (debe ser único dentro de la hoja de cálculo). |
drawing_type | MsoDrawingType | ColladaSaveOptions | El tipo geométrico de esta forma. |
upper_left_row | int | Lectura/Escritura | 0-based row index of the top-left anchor cell. |
upper_left_column | int | Lectura/Escritura | 0-based column index of the top-left anchor cell. |
lower_right_row | int | Lectura/Escritura | 0-based row index of the bottom-right anchor cell. |
lower_right_column | int | Lectura/Escritura | 0-based column index of the bottom-right anchor cell. |
upper_left_row_offset | int | Lectura/Escritura | Desplazamiento de píxeles desde el borde superior de la celda superior izquierda. |
upper_left_column_offset | int | Lectura/Escritura | Desplazamiento de píxeles desde el borde izquierdo de la celda superior izquierda. |
lower_right_row_offset | int | Lectura/Escritura | Desplazamiento de píxeles desde el borde superior de la celda inferior derecha. |
lower_right_column_offset | int | Lectura/Escritura | Desplazamiento de píxeles desde el borde izquierdo de la celda inferior derecha. |
fill | MsoFillFormat | ColladaSaveOptions | Configuración de relleno (fondo). |
line | MsoLineFormat | ColladaSaveOptions | Configuración de contorno/borde. |
text | str | Lectura/Escritura | Contenido de texto mostrado dentro de la forma. |
font | ShapeFont | ColladaSaveOptions | Configuración de fuente para el texto de la forma. |
text_horizontal_alignment | TextAlignmentType | Lectura/Escritura | Alineación horizontal del texto dentro de la forma. |
text_vertical_alignment | TextAnchorType | Lectura/Escritura | Anclaje vertical del texto dentro de la forma. |
is_text_wrapped | bool | Lectura/Escritura | True para ajustar el texto al borde de la forma. |
is_locked | bool | Lectura/Escritura | True para bloquear la forma cuando la protección de la hoja de cálculo está activa. |
is_hidden | bool | Lectura/Escritura | True para ocultar la forma. |
hyperlink | `str | None` | Lectura/Escritura |
ColladaSaveOptions
copy
shape.copy() -> ShapeDevuelve una copia profunda de esta forma con todo el formato preservado.
ShapeCollection
ShapeCollection se accede como ws.shapes. Contiene todas las formas en una hoja de cálculo.
ColladaSaveOptions
add
ws.shapes.add(
drawing_type: MsoDrawingType,
upper_left_row: int,
upper_left_column: int,
lower_right_row: int,
lower_right_column: int
) -> ShapeAgrega una forma del tipo especificado. Todos los argumentos de posición son índices de fila/columna basados en 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
) -> ShapeAtajo para add(MsoDrawingType.TEXT_BOX, ...).
Propiedades e iteración
| ColladaSaveOptions | ColladaSaveOptions |
|---|---|
count | Número de formas en la colección (solo lectura). |
__len__() | ColladaSaveOptions count. |
__iter__() | Itera sobre todas las Shape objetos. |
__getitem__(index) | Devuelve el Shape con base cero index. |
ColladaSaveOptions
Agregar un rectángulo con relleno sólido
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")Agregar un cuadro de texto
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")