XLSXWRITER insert_image not working with BytesIO

803 Views Asked by At

When written directly to xlsx file, insert_image works as intended. But it doesn't work when written to BytesIO object, the image simply doesn't appear.

1

There are 1 best solutions below

0
On

Ok, I had to actually specify image_data parameter for this to work using byte stream.

img = 'img.png'
image_file = open(img, 'rb')
image_data = io.BytesIO(image_file.read())
image_file.close()

ws_dashboard.insert_image('A1',img, {'image_data': image_data, 'x_scale': 0.5, 'y_scale': 0.5})