I want to insert an image to Excel document, and I try to use xlsxwriter insert_image, but it said unknown.insert_image.
from win32com import client
xlApp = client.Dispatch("Excel.Application")
workbook = xlApp.Workbooks.Open('test.xlsx')
worksheet = workbook.Worksheets[0]
worksheet.insert_image('F4','logo.png')
worksheet.Visible = 1
worksheet.ExportAsFixedFormat(0, 'D:\\Python\\whatever\\test.pdf')
workbook.close()
it raised
Exception "unhandled AttributeError" unknown.insert_image
You are mixing 2 incompatible objects in this example client.Dispatch("Excel.Application").Workbooks.Open('name')
and xlsxwriter.Workbook
.
You need to use the equivalent method to xlsxwriter.worksheet.insert_image()
in the other object/class.
Maybe try the syntax from this answer.