Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Hey guys. I am fairly new to python and was wondering if you could help me with

ID: 667388 • Letter: H

Question

Hey guys. I am fairly new to python and was wondering if you could help me with a problem I have here.

So for part of a project I have to do, I have to have python run on its own and then update a spreadsheet every time it runs. So for example, when python first runs on its own, I want python to insert ONLY my string into cell A1, but the next time it runs I want python to insert ONLY my string into cell B1 while keeping the previous data in cell A1 and so on until column 27. When it hits column 27 I want it to jump down a row and continue doing this for 300 rows.

I know I'm going to need some sort of loop for this but just can't figure it out. So far I have something like this:

for i in range (2,300):

for j in range (2,27):

Sheet.cell(row=i, column=j).value = my_string[5:-7]

Thanks in advance!

Explanation / Answer

import xlsxwriter
workbook = xlsxwriter.Workbook('chegg.xlsx') #opening excel sheet
worksheet = workbook.add_worksheet() #creating worksheet
for i in range (2,300): # this fills rows upto 300
for j in range (2,27): #this fills columns upto 28
worksheet.write(i, j, "My_String") # write string