Shape

aspose-cells-foss prend en charge l’ajout de formes géométriques et de zones de texte aux feuilles de calcul via le ShapeCollection (ws.shapes). Chaque forme est représentée par un Shape objet avec des propriétés de remplissage, de ligne et de texte configurables.

ColladaSaveOptions: aspose.cells_foss

from aspose.cells_foss import (
    MsoDrawingType, FillType, MsoLineDashStyle,
    TextAlignmentType, TextAnchorType,
    MsoFillFormat, MsoLineFormat, ShapeFont, Shape,
)

MsoDrawingType

MsoDrawingType est un IntEnum identifiant le type de forme géométrique.

NameTypeAccessDescription
upper_left_row``Read/WriteGets or sets the upper left row.
upper_left_column``Read/WriteGets or sets the upper left column.
lower_right_row``Read/WriteGets or sets the lower right row.
lower_right_column``Read/WriteGets or sets the lower right column.
upper_left_row_offset``Read/WriteGets or sets the upper left row offset.
upper_left_column_offset``Read/WriteGets or sets the upper left column offset.
lower_right_row_offset``Read/WriteGets or sets the lower right row offset.
lower_right_column_offset``Read/WriteGets or sets the lower right column offset.
name``ReadGets the name.
drawing_type``ReadGets the drawing type.
fill``ReadGets the fill.
line``ReadGets the line.
text``ReadGets the text.
font``ReadGets the font.
text_horizontal_alignment``ReadGets the text horizontal alignment.
text_vertical_alignment``ReadGets the text vertical alignment.
is_text_wrapped``ReadGets the is text wrapped.
is_locked``ReadGets the is locked.
is_hidden``ReadGets the is hidden.
placement``ReadGets the placement.
hyperlink``ReadGets the hyperlink.

FillType

FillType est un IntEnum identifiant le type de remplissage appliqué à une forme.

SignatureDescription
__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 est un IntEnum pour le motif de tirets de la ligne de bordure/contour.


TextAlignmentType

TextAlignmentType est un IntEnum pour l’alignement horizontal du texte à l’intérieur d’une forme.


TextAnchorType

TextAnchorType est un IntEnum pour l’ancrage vertical du texte à l’intérieur d’une forme.


MsoFillFormat

Contrôle l’apparence du remplissage d’une forme. Accessible via shape.fill.

ColladaSaveOptions

ColladaSaveOptions

copy

fill.copy() -> MsoFillFormat

Renvoie une copie profonde de ces paramètres de remplissage.


MsoLineFormat

Contrôle l’apparence du contour/bordure d’une forme. Accessible via shape.line.

ColladaSaveOptions

ColladaSaveOptions

copy

line.copy() -> MsoLineFormat

Renvoie une copie profonde de ces paramètres de ligne.


ShapeFont

Contrôle la police du texte à l’intérieur d’une forme. Accessible via shape.font.

ColladaSaveOptions

ColladaSaveOptions

copy

font.copy() -> ShapeFont

Renvoie une copie profonde de ces paramètres de police.


ColladaSaveOptions

Shape les objets ne sont pas construits directement. Utilisez ws.shapes.add(...) ou ws.shapes.add_text_box(...).

ColladaSaveOptions

ColladaSaveOptions

copy

shape.copy() -> Shape

Renvoie une copie profonde de cette forme avec tous les formats préservés.


ShapeCollection

ShapeCollection est accessible comme ws.shapes. Il contient toutes les formes d’une feuille de calcul.

ColladaSaveOptions

add

ws.shapes.add(
    drawing_type: MsoDrawingType,
    upper_left_row: int,
    upper_left_column: int,
    lower_right_row: int,
    lower_right_column: int
) -> Shape

Ajoute une forme du type spécifié. Tous les arguments de position sont des indices de ligne/colonne à base zéro.

add_text_box

ws.shapes.add_text_box(
    upper_left_row: int,
    upper_left_column: int,
    lower_right_row: int,
    lower_right_column: int
) -> Shape

Raccourci pour add(MsoDrawingType.TEXT_BOX, ...).

Propriétés et itération


ColladaSaveOptions

Ajouter un rectangle avec remplissage uni

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")

Ajouter une zone de texte

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")

Voir aussi

 Français