0

Context

Got a variable Output that contains text mentioned below. However, I want to insert each Output line on each A-row in Excel. How do I do this?

Output

  • Text 1
  • Text 2
  • Text 3

Current Code

# Open Workbook
wb = load_workbook('Fortimail-config.xlsx')
ws = wb.active

# Create a workbook sheet name.
sheet = wb['Sheet']

sheet.cell(row=1, column=1).value = output

wb.save("Fortimail-config.xlsx")

What I get

  • A1 = Text 1 Text 2 Text 3

What I want

  • A1 = Text 1
  • A2 = Text 2
  • A3 = Text 3
0

1 Answer 1

1

sheet.cell(row=1, column=1).value = output here the code is assigning value to row 1 and column 1. Therefore this will map to excel cell A1

Assuming output variable is an array; you can append it to the sheet using sheet.append() and it will add the array to each row.

For example:

output = ['Text 1', 'Text 2', 'Text 3']

wb = load_workbook('Fortimail-config.xlsx')
ws = wb.active

# Create a workbook sheet name.
sheet = wb['Sheet']

sheet.append(output)

wb.save("Fortimail-config.xlsx")
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you for the advice and your answer. I just tried it your way but the data is now moving from A1 B1 C1 etc.
sorry I may have misread the question. If you replace output = ['Text 1', 'Text 2', 'Text 3'] with output = [['Text 1', 'Text 2', 'Text 3']] (double brackets) you should see all data on row A

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.