1

I'm new to using openpyxl, and I have a list of data I want to add to a specific column/row in excel. I know how to add a value to a specific cell using sheet.append, but this only allows you to change 1 cell to a specific value. Let's say this is my spreadsheet: spreadsheet. I want to add the list of values [5, 7, 8] to the column oranges. How would I do this? I'm assuming i would iterate of the list and use the sheet.append function.

Vijay
  • 143
  • 1
  • 1
  • 10
Conweezy
  • 105
  • 5
  • 15

1 Answers1

1

Use a for loop. To insert values starting from row 3, column C from your_list:

from openpyxl import Workbook

wb = Workbook()
ws = wb.worksheets[0]

your_list = [5,7,8]
row_number = 3
your_column = 3
for i, value in enumerate(your_list, start=row_number):
    ws.cell(row=i, column=your_column).value = value

wb.save("column_values.xlsx")

ConSod
  • 743
  • 8
  • 18