Shape — Aspose.Cells FOSS for Python API Reference
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 ที่ระบุประเภทของรูปทรงเรขาคณิต.
| Properties | Properties | Properties | Properties |
|---|---|---|---|
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 เป็น an IntEnum ที่ระบุประเภทของการเติมที่ใช้กับรูปทรง.
| Properties | Properties |
|---|---|
NONE | 0 |
SOLID | 1 |
GRADIENT | 2 |
PATTERN | 3 |
AUTOMATIC | 4 |
MsoLineDashStyle
MsoLineDashStyle เป็น an IntEnum สำหรับรูปแบบเส้นประของขอบ/โครงร่าง.
| Properties | Properties |
|---|---|
SOLID | 0 |
DASH | 1 |
DOT | 2 |
DASH_DOT | 3 |
DASH_DOT_DOT | 4 |
LONG_DASH | 5 |
LONG_DASH_DOT | 6 |
TextAlignmentType
TextAlignmentType เป็น an IntEnum สำหรับการจัดแนวข้อความในแนวนอนภายในรูปทรง.
| Properties | Properties |
|---|---|
LEFT | 0 |
CENTER | 1 |
RIGHT | 2 |
JUSTIFY | 3 |
DISTRIBUTED | 4 |
TextAnchorType
TextAnchorType เป็น an IntEnum สำหรับการยึดข้อความในแนวตั้งภายในรูปทรง.
| Properties | Properties |
|---|---|
TOP | 0 |
MIDDLE | 1 |
BOTTOM | 2 |
JUSTIFIED | 3 |
MsoFillFormat
ควบคุมลักษณะการเติมของรูปทรง. สามารถเข้าถึงได้ผ่าน shape.fill.
Properties
| Properties | Properties | Properties |
|---|---|---|
fill_type | FillType | ประเภทการเติมที่ใช้งานอยู่. |
fore_color | str | สีการเติมพื้นหน้า (หลัก) ในรูปแบบ RRGGBB hex. |
transparency | float | ความทึบของการเติมเป็นค่าจาก 0.0 (ทึบเต็ม) ถึง 1.0 (โปร่งใสเต็ม). |
Properties
คัดลอก
fill.copy() -> MsoFillFormatคืนค่าการคัดลอกเชิงลึกของการตั้งค่าการเติมเหล่านี้.
MsoLineFormat
ควบคุมลักษณะของเส้นขอบ/ขอบเขตของรูปทรง เข้าถึงได้ผ่าน shape.line.
Properties
| Properties | Properties | Properties |
|---|---|---|
is_visible | bool | True เพื่อวาดโครงร่างของรูปทรง. |
color | str | สีโครงร่างเป็นรหัสสี RRGGBB แบบ hex. |
weight | int | ความหนาของโครงร่าง (ความหนา) หน่วยเป็นพอยต์. |
dash_style | MsoLineDashStyle | รูปแบบเส้นประสำหรับโครงร่าง. |
transparency | float | ความทึบของโครงร่างจาก 0.0 (ทึบ) ถึง 1.0 (โปร่งใส). |
Properties
คัดลอก
line.copy() -> MsoLineFormatคืนค่าการคัดลอกเชิงลึกของการตั้งค่าเส้นเหล่านี้.
ShapeFont
ควบคุมแบบอักษรของข้อความภายในรูปทรง เข้าถึงได้ผ่าน shape.font.
Properties
| Properties | Properties | Properties |
|---|---|---|
name | str | ชื่อฟอนต์ (เช่น,., "Calibri"). |
size | float | ขนาดฟอนต์เป็นพอยต์. |
bold | bool | True สำหรับน้ำหนักหนา. |
italic | bool | True สำหรับสไตล์เอียง. |
underline | bool | True สำหรับขีดเส้นเดี่ยว. |
color | str | สีฟอนต์เป็นรหัสสี RRGGBB แบบ hex. |
Properties
คัดลอก
font.copy() -> ShapeFontคืนค่าการคัดลอกเชิงลึกของการตั้งค่าแบบอักษรเหล่านี้.
Properties
Shape อ็อบเจกต์ไม่ถูกสร้างโดยตรง ใช้ ws.shapes.add(...) หรือ ws.shapes.add_text_box(...).
Properties
| Properties | Properties | Properties | Properties |
|---|---|---|---|
name | str | อ่าน/เขียน | ชื่อรูปร่าง (ต้องไม่ซ้ำกันภายในแผ่นงาน). |
drawing_type | MsoDrawingType | Properties | ประเภทเรขาคณิตของรูปร่างนี้. |
upper_left_row | int | อ่าน/เขียน | 0-based row index of the top-left anchor cell. |
upper_left_column | int | อ่าน/เขียน | 0-based column index of the top-left anchor cell. |
lower_right_row | int | อ่าน/เขียน | 0-based row index of the bottom-right anchor cell. |
lower_right_column | int | อ่าน/เขียน | 0-based column index of the bottom-right anchor cell. |
upper_left_row_offset | int | อ่าน/เขียน | การเลื่อนพิกเซลจากขอบบนของเซลล์ซ้ายบน. |
upper_left_column_offset | int | อ่าน/เขียน | การเลื่อนพิกเซลจากขอบซ้ายของเซลล์ซ้ายบน. |
lower_right_row_offset | int | อ่าน/เขียน | การเลื่อนพิกเซลจากขอบบนของเซลล์ขวาล่าง. |
lower_right_column_offset | int | อ่าน/เขียน | การเลื่อนพิกเซลจากขอบซ้ายของเซลล์ขวาล่าง. |
fill | MsoFillFormat | Properties | การตั้งค่าการเติม (พื้นหลัง). |
line | MsoLineFormat | Properties | การตั้งค่าโครงร่าง/ขอบ. |
text | str | อ่าน/เขียน | เนื้อหาข้อความที่แสดงภายในรูปร่าง. |
font | ShapeFont | Properties | การตั้งค่าแบบอักษรสำหรับข้อความในรูปร่าง. |
text_horizontal_alignment | TextAlignmentType | อ่าน/เขียน | การจัดแนวข้อความแนวนอนภายในรูปร่าง. |
text_vertical_alignment | TextAnchorType | อ่าน/เขียน | การยึดข้อความแนวตั้งภายในรูปร่าง. |
is_text_wrapped | bool | อ่าน/เขียน | True เพื่อบรรจุข้อความที่ขอบของรูปร่าง. |
is_locked | bool | อ่าน/เขียน | True เพื่อล็อครูปร่างเมื่อการป้องกันแผ่นงานทำงานอยู่. |
is_hidden | bool | อ่าน/เขียน | True เพื่อซ่อนรูปร่าง. |
hyperlink | `str | None` | อ่าน/เขียน |
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 | Properties |
|---|---|
count | จำนวนรูปร่างในคอลเลกชัน (อ่านอย่างเดียว). |
__len__() | Properties count. |
__iter__() | วนซ้ำผ่านทั้งหมด Shape วัตถุ. |
__getitem__(index) | คืนค่า Shape โดยเริ่มจากศูนย์ index. |
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")