how to append data using openpyxl python to excel file from a specified row?

前端 未结 4 675
心在旅途
心在旅途 2020-12-28 23:32

I have different Python list variables(data1, data2, data3 ect) containing data which I want to put into an already existing excel sheet. Presently My loop goes like this.

4条回答
  •  悲&欢浪女
    2020-12-28 23:56

    You can use the append() method to append values to the existing excel files. Example:

    workbook_obj = openpyxl.load_workbook(excelFilePath)
    sheet_obj = workbook_obj.active
    col1 = 'NewValueCol1'
    col2 = 'NewValueCol2'
    sheet_obj.append([col1, col2])
    workbook_obj.save(excelFilePath)
    

    here the col1 and col2 values will be added with the existing data in the excel sheet.

提交回复
热议问题