Replace the text of a paragraph in a slide. Args: slide (SlidePage): The slide containing the paragraph. div_id (int): The ID of the division containing the paragraph. paragraph_id (int): The ID of the paragraph to replace. text (str): The new text to replac
(slide: SlidePage, div_id: int, paragraph_id: int, text: str)
| 245 | |
| 246 | |
| 247 | def replace_paragraph(slide: SlidePage, div_id: int, paragraph_id: int, text: str): |
| 248 | """ |
| 249 | Replace the text of a paragraph in a slide. |
| 250 | |
| 251 | Args: |
| 252 | slide (SlidePage): The slide containing the paragraph. |
| 253 | div_id (int): The ID of the division containing the paragraph. |
| 254 | paragraph_id (int): The ID of the paragraph to replace. |
| 255 | text (str): The new text to replace with. |
| 256 | |
| 257 | Raises: |
| 258 | IndexError: If the paragraph is not found. |
| 259 | """ |
| 260 | shape = element_index(slide, div_id) |
| 261 | assert ( |
| 262 | shape.text_frame.is_textframe |
| 263 | ), "The element does not have a text frame, please check the element id and type of element." |
| 264 | for para in shape.text_frame.paragraphs: |
| 265 | if para.idx == paragraph_id: |
| 266 | para.text = text |
| 267 | shape._closures["replace"].append( |
| 268 | Closure( |
| 269 | partial(replace_para, para.real_idx, text), |
| 270 | para.real_idx, |
| 271 | ) |
| 272 | ) |
| 273 | return |
| 274 | else: |
| 275 | raise IndexError( |
| 276 | f"Cannot find the paragraph {paragraph_id} of the element {div_id}," |
| 277 | "Please: " |
| 278 | "1. check if you refer to a non-existed paragraph." |
| 279 | "2. check if you already deleted it." |
| 280 | ) |
| 281 | |
| 282 | |
| 283 | def replace_image(slide: SlidePage, img_id: int, image_path: str): |
nothing calls this directly
no test coverage detected