'writing image to excel with xlsxwriter returns " workbook not callable"

Using the first answer to the following link Python: Writing Images and dataframes to the same excel file as a guide:

I have the following script in which I like to write a dataframe object to one sheet and a bunch of images to another sheet.

class name():

 def some_func(self):
     self.writer = pd.ExcelWriter('Name1',engine='xlsxwriter')
     return
 
 def write_excel(self):
     self.df.to_excel(self.writer,sheet_name='Name',index=False, header=False)
     self.writer.save()   
    return

def write_excel(self):
    self.workbook = self.writer.book('Name1')
    self.worksheet = self.writer.sheets(name='images')
    images=[]
    do some stuff
    for i,image in enumerate(images):
        self.worksheet.insert_image('D1',0,y_postn[i],image)  
    self.writer.save()   
    return

It returns the following error

'Workbook' object is not callable

Not sure how to interpret this error or fix it?...



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source