0

Im trying to write to an excel based of a list that I have. The problem is that I cannot get it into a list (A1, A2, A3, A4 etc) in excel, all values is written in one cell.

Any thoughts? I cannot find any good example, is "writing python list to excel" the wrong explanation?

import requests
from xlwt import Workbook

url = 'some website'

r = requests.get(url)
split_text = r.text.split()

exit_address = []
for idx, val in enumerate(split_text):
  if split_text[idx-1] == 'ExitAddress':
    exit_address.append(val)

wb = Workbook()
sheet1 = wb.add_sheet('Sheet 1')
sheet1.write(0,0, exit_address)

wb.save('nodes.xlsx')

Thanks in advance

1 Answer 1

1

That's because you specified to write the entire list to the first cell:

sheet1.write(0,0, exit_address)

You can try something like this instead:

import requests
from xlwt import Workbook

url = 'some website'

r = requests.get(url)
split_text = r.text.split()

exit_address = []
for idx, val in enumerate(split_text):
  if split_text[idx-1] == 'ExitAddress':
    exit_address.append(val)

wb = Workbook()
sheet1 = wb.add_sheet('Sheet 1')

for i, text in enumerate(exit_address):
    sheet1.write(i, 0, text)

wb.save('nodes.xlsx')

https://xlwt.readthedocs.io/en/latest/api.html

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.