1

I am starting with Python and I am running into difficulty. I am trying to pass the result of a loop in Python to a specific sheet and column of an Excel file.

I am doing it with XlsWriter but it doesn't work. For example, if you want to pass the result of this loop of random numbers, what is wrong with this code?

Example:

import xlsxwriter  
workbook = xlsxwriter.Workbook(r'C:\Users\Me\Downloads\ej.xlsx')
worksheet = workbook.add_worksheet("Hoja1")
worksheet.write('A1', 'NUMEROS')
from random import seed
from random import random
seed(1)
row =0
for _ in range(5):
    value = random()
    worksheet.write(row, 1, value)
    row += 1    
    print(value)

Sorry for my English, I am not a native speaker.

Thanks a lot.

1 Answer 1

1

You need to close it.

import xlsxwriter  
workbook = xlsxwriter.Workbook(r'C:\Users\Me\Downloads\ej.xlsx')
worksheet = workbook.add_worksheet("Hoja1")
worksheet.write('A1', 'NUMEROS')
from random import seed
from random import random
seed(1)
row =0
for _ in range(5):
    value = random()
    worksheet.write(row, 1, value)
    row += 1    
    print(value)

workbook.close()
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.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.