MCPcopy
hub / github.com/jmcnamara/XlsxWriter / insert_image

Method insert_image

xlsxwriter/worksheet.py:1557–1592  ·  view source on GitHub ↗

Insert an image with its top-left corner in a worksheet cell. Args: row: The cell row (zero indexed). col: The cell column (zero indexed). source: Filename, BytesIO, or Image object. options: Position, scale, url and data

(
        self,
        row: int,
        col: int,
        source: Union[str, BytesIO, Image],
        options: Optional[Dict[str, Any]] = None,
    )

Source from the content-addressed store, hash-verified

1555
1556 @convert_cell_args
1557 def insert_image(
1558 self,
1559 row: int,
1560 col: int,
1561 source: Union[str, BytesIO, Image],
1562 options: Optional[Dict[str, Any]] = None,
1563 ) -> Literal[0, -1]:
1564 """
1565 Insert an image with its top-left corner in a worksheet cell.
1566
1567 Args:
1568 row: The cell row (zero indexed).
1569 col: The cell column (zero indexed).
1570 source: Filename, BytesIO, or Image object.
1571 options: Position, scale, url and data stream of the image.
1572
1573 Returns:
1574 0: Success.
1575 -1: Row or column is out of worksheet bounds.
1576
1577 """
1578 # Check insert (row, col) without storing.
1579 if self._check_dimensions(row, col, True, True):
1580 warn(f"Cannot insert image at ({row}, {col}).")
1581 return -1
1582
1583 # Convert the source to an Image object.
1584 image = self._image_from_source(source, options)
1585
1586 image._row = row
1587 image._col = col
1588 image._set_user_options(options)
1589
1590 self.images.append(image)
1591
1592 return 0
1593
1594 @convert_cell_args
1595 def embed_image(

Callers 15

test_create_fileMethod · 0.80
test_create_fileMethod · 0.80
test_create_fileMethod · 0.80
test_create_fileMethod · 0.80
test_create_fileMethod · 0.80
test_create_fileMethod · 0.80
test_create_fileMethod · 0.80
test_create_fileMethod · 0.80
test_create_fileMethod · 0.80

Calls 3

_check_dimensionsMethod · 0.95
_image_from_sourceMethod · 0.95
_set_user_optionsMethod · 0.45

Tested by 15

test_create_fileMethod · 0.64
test_create_fileMethod · 0.64
test_create_fileMethod · 0.64
test_create_fileMethod · 0.64
test_create_fileMethod · 0.64
test_create_fileMethod · 0.64
test_create_fileMethod · 0.64
test_create_fileMethod · 0.64
test_create_fileMethod · 0.64