jmcnamara / XlsxWriter

A Python module for creating Excel XLSX files.
https://xlsxwriter.readthedocs.io
BSD 2-Clause "Simplified" License
3.66k stars 632 forks source link

question: <Image Insertion and Position> #1058

Closed asthaawasthi-laitkor closed 7 months ago

asthaawasthi-laitkor commented 7 months ago

Question

I am using xlsxwriter for generating report , i have inserted one image , i am trying to scale it by x_scale 63% and y_scale :62% , and want to put my image in center of three row (Row height of each row is 40, column width is 22.50), but unable to insert it perfectly , in my generated xlsx file the scaling factor got changed , please provide a solution for problem

worksheet.insert_image("B2", filename, {"image_data": image_data, 'x_offset': 17.0, 'y_offset': 7.0, 'x_scale': 0.61, 'y_scale': 0.55})
jmcnamara commented 7 months ago

A better way to do this is probably with the embed_image() method. This requires the latest version of XlsxWriter:

https://xlsxwriter.readthedocs.io/worksheet.html#worksheet-embed-image

Can you try that and see if it suits you requirements better?

asthaawasthi-laitkor commented 7 months ago

@jmcnamara thank you for your response, I am using XlsxWriter==3.1.9 , and this embed_image() function doesn't work for me. also I have set DPI 96 of an inserted image and using x_offset ,y_offset only but it scaled my actual size of image . Ref: https://xlsxwriter.readthedocs.io/working_with_object_positioning.html#image-sizing-and-dpi

jmcnamara commented 7 months ago

I am using XlsxWriter==3.1.9 , and this embed_image() function doesn't work for me.

Could you try version 3.2.0?

asthaawasthi-laitkor commented 7 months ago

@jmcnamara Thank you for your valuable time , now issue got fixed

asthaawasthi-laitkor commented 6 months ago

I am using XlsxWriter==3.1.9 , and this embed_image() function doesn't work for me.

Could you try version 3.2.0?

Hi @jmcnamara , i used embed_image version 3.2.0 , this works fine with windows but in mac with ms office 365 ,showing error image

jmcnamara commented 6 months ago

this works fine with windows but in mac with ms office 365 ,showing error

That error usually means that the version of Excel doesn't support that feature and needs to be upgraded. You can test that by trying to manually insert an image using the Excel Pictures -> Place in Cell" option. If the version of Excel doesn't have that option, or it doesn't work, then you will need to upgrade Excel.