DD08
DD08

Reputation: 77

Xlwings Add picture throws error "pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, None, "The specified file wasn't found.")

I am using xlwings to add picture in excel file, which throws the error

pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, None, "The specified file wasn't found.", None, 0, -2146827284), None)

So far I have tried all of the below options.

ws.pictures.add(path to png file, name=xyz, update=True, 
                left=ws.range('B2').left, top=ws.range('B2').top)

ws.pictures.add(path to png file, sheet=sheetName)

rng = wb.sheets[sheetName].range("A1")
xw.Picture.add(path to png file, top=rng.top, left=rng.left)

ws.pictures.add(path to png file)

Upvotes: 0

Views: 447

Answers (1)

moken
moken

Reputation: 6620

Of each of the lines you tried

This will work

ws.pictures.add(path to png file, name=xyz, update=True, 
                left=ws.range('B2').left, top=ws.range('B2').top)

This wont work, there is no 'sheet=' argument for pictures.add

ws.pictures.add(path to png file, sheet=sheetName)

This wont work, xw.Picture does not have an attribute add

xw.Picture.add(path to png file, top=rng.top, left=rng.left)

This line will work

ws.pictures.add(path to png file)

However your main issue is presumably path to png file. You don't specify how you are setting this but for simplicity;

These two will work:

path_to_png_file = "C:\\Temp\image.png"
path_to_png_file = r"C:\Temp\image.png"

but this will give you the 'The specified file wasn't found' error:

path_to_png_file = "C:/Temp/image.png"

Upvotes: 1

Related Questions