def save_file(self): workbook = xlsxwriter.Workbook('Myfile.xlsx') worksheet = workbook.add_worksheet() for x in range(self.table.rowCount()): data = [] for y in range(self.table.columnCount()): item_data = self.table.item(x, y) if item_data is not None: data.append(item_data) worksheet.insert_image('A1', data) 

Gives an error message:

TypeError: argument should be string, bytes or integer, not list

  • 2
    1) Which line of code caused the error? 2) What word in the error message could not be translated? - Akina

1 answer 1

The insert_image method has the following form:

 insert_image(row, col, image[, options]) 

And instead of a line with the name of a picture ( image ) you are passing a list of data , which causes an error. To fix, you need to specify which element from this list to use, i.e. something like that:

 worksheet.insert_image('A1', data[0]) 
  • Thank you, but the problem turned out to be deeper - Dr.robot
  • Now it gives the following error: IndexError: list index out of range - Dr.robot
  • @ Dr.robot and what is the question? You specify an index that goes beyond the array, so you get this error. - Edward Izmalkov