-1

I have a list of data which I want to write into a specific column (B2 column) in Excel

Input example:

mydata =[12,13,14,15]

Desired Output in Excel:

A2| B2| 
  | 12|    
  | 13|
  | 14|
  | 15|

I have tried using openpyxl to access the specific sheet (which works fine) and specific cell(B2) but it throws an error to write to the excel file as it is a list. It works fine if I assign a single value as shown in the code extract below:

mydata= my_wb['sheet2']['B2'] = 4

Can anyone point me in the right direction?

2
  • 2
    should every number go into b2? Or b2, b3, b4 and so on? Commented Oct 28, 2021 at 15:55
  • yes that's correct b2,b3 etc @ph140 Commented Oct 28, 2021 at 15:57

1 Answer 1

1

Iterate over the list and paste each value into the desired row in column B:

for i, n in enumerate(mydata):
    my_wb["sheet2"].cell(i+2, 2).value = n
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.