Shape

aspose-cells-foss รองรับการเพิ่มรูปทรงเรขาคณิตและกล่องข้อความลงในแผ่นงานผ่าน the ShapeCollection (ws.shapes). แต่ละรูปทรงจะถูกแทนด้วย a Shape object ที่มีคุณสมบัติการเติม, เส้น, และข้อความที่สามารถกำหนดค่าได้.

Properties: aspose.cells_foss

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

MsoDrawingType

MsoDrawingType เป็น an IntEnum ที่ระบุประเภทของรูปทรงเรขาคณิต.

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 เป็น an IntEnum ที่ระบุประเภทของการเติมที่ใช้กับรูปทรง.

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 เป็น an IntEnum สำหรับรูปแบบเส้นประของขอบ/โครงร่าง.


TextAlignmentType

TextAlignmentType เป็น an IntEnum สำหรับการจัดแนวข้อความในแนวนอนภายในรูปทรง.


TextAnchorType

TextAnchorType เป็น an IntEnum สำหรับการยึดข้อความในแนวตั้งภายในรูปทรง.


MsoFillFormat

ควบคุมลักษณะการเติมของรูปทรง. สามารถเข้าถึงได้ผ่าน shape.fill.

Properties

Properties

คัดลอก

fill.copy() -> MsoFillFormat

คืนค่าการคัดลอกเชิงลึกของการตั้งค่าการเติมเหล่านี้.


MsoLineFormat

ควบคุมลักษณะของเส้นขอบ/ขอบเขตของรูปทรง เข้าถึงได้ผ่าน shape.line.

Properties

Properties

คัดลอก

line.copy() -> MsoLineFormat

คืนค่าการคัดลอกเชิงลึกของการตั้งค่าเส้นเหล่านี้.


ShapeFont

ควบคุมแบบอักษรของข้อความภายในรูปทรง เข้าถึงได้ผ่าน shape.font.

Properties

Properties

คัดลอก

font.copy() -> ShapeFont

คืนค่าการคัดลอกเชิงลึกของการตั้งค่าแบบอักษรเหล่านี้.


Properties

Shape อ็อบเจกต์ไม่ถูกสร้างโดยตรง ใช้ ws.shapes.add(...) หรือ ws.shapes.add_text_box(...).

Properties

Properties

คัดลอก

shape.copy() -> Shape

คืนค่าการคัดลอกเชิงลึกของรูปทรงนี้พร้อมกับการจัดรูปแบบทั้งหมดที่คงไว้.


ShapeCollection

ShapeCollection เข้าถึงได้เป็น ws.shapes. มีรูปร่างทั้งหมดบนแผ่นงาน.

Properties

add

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

เพิ่มรูปของประเภทที่ระบุ. ทุกอาร์กิวเมนต์ตำแหน่งใช้ดัชนีแถว/คอลัมน์ที่เริ่มจาก 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
) -> Shape

ทางลัดสำหรับ add(MsoDrawingType.TEXT_BOX, ...).

คุณสมบัติและการวนซ้ำ


Properties

เพิ่มสี่เหลี่ยมผืนผ้าพร้อมการเติมสีทึบ

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

เพิ่มกล่องข้อความ

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

ดูเพิ่มเติม

 ภาษาไทย