Edit properties of an existing textbox shape. :param shape: The shape object (textbox) to edit. :param text: New text to set. If None, leaves text unmodified. :param word_wrap: Boolean to enable/disable word wrap. If None, leaves unmodified. :param font_size: Font size (int/flo
(
shape,
text=None,
word_wrap=None,
font_size=None,
bold=None,
italic=None,
alignment=None,
fill_color=None,
font_name=None
)
| 1479 | |
| 1480 | |
| 1481 | def edit_textbox( |
| 1482 | shape, |
| 1483 | text=None, |
| 1484 | word_wrap=None, |
| 1485 | font_size=None, |
| 1486 | bold=None, |
| 1487 | italic=None, |
| 1488 | alignment=None, |
| 1489 | fill_color=None, |
| 1490 | font_name=None |
| 1491 | ): |
| 1492 | """ |
| 1493 | Edit properties of an existing textbox shape. |
| 1494 | |
| 1495 | :param shape: The shape object (textbox) to edit. |
| 1496 | :param text: New text to set. If None, leaves text unmodified. |
| 1497 | :param word_wrap: Boolean to enable/disable word wrap. If None, leaves unmodified. |
| 1498 | :param font_size: Font size (int/float or string like '12pt'). If None, leaves unmodified. |
| 1499 | :param bold: Boolean to set bold. If None, leaves unmodified. |
| 1500 | :param italic: Boolean to set italic. If None, leaves unmodified. |
| 1501 | :param alignment: One of 'left', 'center', 'right', 'justify'. If None, leaves unmodified. |
| 1502 | :param fill_color: A tuple (r, g, b) for background fill color, or None to leave unmodified. |
| 1503 | """ |
| 1504 | |
| 1505 | text_frame = shape.text_frame |
| 1506 | text_frame.auto_size = MSO_AUTO_SIZE.NONE |
| 1507 | |
| 1508 | # Update fill color if provided |
| 1509 | if fill_color is not None: |
| 1510 | shape.fill.solid() |
| 1511 | shape.fill.fore_color.rgb = RGBColor(*fill_color) |
| 1512 | # else: If you'd like to remove any existing fill if None, you could: |
| 1513 | # else: |
| 1514 | # shape.fill.background() |
| 1515 | |
| 1516 | # Update word wrap if provided |
| 1517 | if word_wrap is not None: |
| 1518 | text_frame.word_wrap = word_wrap |
| 1519 | |
| 1520 | # If text is provided, clear existing paragraphs and add the new text |
| 1521 | if text is not None: |
| 1522 | text_frame.clear() |
| 1523 | p = text_frame.add_paragraph() |
| 1524 | run = p.add_run() |
| 1525 | run.text = text |
| 1526 | |
| 1527 | # If alignment is provided, apply to the paragraph |
| 1528 | if alignment is not None: |
| 1529 | p.alignment = _parse_alignment(alignment) |
| 1530 | |
| 1531 | # If font formatting info is provided, apply to the run font |
| 1532 | font = run.font |
| 1533 | if font_size is not None: |
| 1534 | font.size = _parse_font_size(font_size) |
| 1535 | if bold is not None: |
| 1536 | font.bold = bold |
| 1537 | if italic is not None: |
| 1538 | font.italic = italic |
nothing calls this directly
no test coverage detected