0
import xlsxwriter
row = 0
col = 0
a = ['1', '2', '3','4','5']
with xlsxwriter.Workbook('D:\\Master\\Codingfiles\\' + 'SSDATA5.xlsx') as workbook:
    worksheet1 = workbook.add_worksheet
    for x in a:
        worksheet1.write(row, col,x)
        row+=1

Hi i am a beginner,When i run this code it runs properly and write in values from 'a' in first 5 rows of excel sheet but I want to create a code using nested loop like this

import xlsxwriter
row = 0
col = 0
a = ['1', '2', '3','4','5']
with xlsxwriter.Workbook('D:\\Master\\Codingfiles\\' + 'SSDATA5.xlsx') as workbook:
    worksheet1 = workbook.add_worksheet()
for i in a:
    for x in a:
        worksheet1.write(row, col,x)
        row+=1

This code does not write above data in excel sheet. Please Help me

1
  • You should probably tag the programming language you are using so the SME can be alerted. Commented Oct 5, 2021 at 19:29

2 Answers 2

2

In python intendation matters, so try:

import xlsxwriter
row = 0
col = 0
a = ['1', '2', '3','4','5']
with xlsxwriter.Workbook('D:\\Master\\Codingfiles\\' + 'SSDATA5.xlsx') as workbook:
    worksheet1 = workbook.add_worksheet()
    for i in a:
        for x in a:
            worksheet1.write(row, col,x)
            row+=1

More: https://www.geeksforgeeks.org/indentation-in-python/

Sign up to request clarification or add additional context in comments.

Comments

0

Seems like your for loop from the second code is not tabbed properly, and is outside with.

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.