1##############################################################################
2#
3# An example of inserting images into a worksheet using the XlsxWriter
4# Python module.
5#
6# Copyright 2013-2021, John McNamara, jmcnamara@cpan.org
7#
8import xlsxwriter
9
10
11# Create an new Excel file and add a worksheet.
12workbook = xlsxwriter.Workbook('images.xlsx')
13worksheet = workbook.add_worksheet()
14
15# Widen the first column to make the text clearer.
16worksheet.set_column('A:A', 30)
17
18# Insert an image.
19worksheet.write('A2', 'Insert an image in a cell:')
20worksheet.insert_image('B2', 'python.png')
21
22# Insert an image offset in the cell.
23worksheet.write('A12', 'Insert an image with an offset:')
24worksheet.insert_image('B12', 'python.png', {'x_offset': 15, 'y_offset': 10})
25
26# Insert an image with scaling.
27worksheet.write('A23', 'Insert a scaled image:')
28worksheet.insert_image('B23', 'python.png', {'x_scale': 0.5, 'y_scale': 0.5})
29
30workbook.close()
31