I have a question about creating an Excel file!!!

Asked 1 years ago, Updated 1 years ago, 129 views

import openpyxl

# You must create an empty excel file named sample.xlsx in the same folder as the py file.
excel_document = openpyxl.load_workbook('same.xlsx')

sheet1 = excel_document.get_sheet_by_name('TEST')

initSet = ['0.1','0.2','0.3','0.4']

list = [[0.1,0.2,0.3],[0.1,0.3,0.6],[0.2,1.4,0.3],[1.6,1.4,1.5,1,1,1,1,1]

for i in range(0,initSet.__len__()):
    sheet1.cell(i+1,1).value = initSet [i]


for col in range(0,list.__len__()) :
    for row in range(0,list[col].__len__()):
        sheet1.cell(row+2,col+1).value = list[row][col]


excel_document.save("TEST.xlsx")
excel_document.close()

The for statement initSet part appears on SyntaxError: invalid syntax.

The for statement below says that the range setting is wrong, so please solve and explain the error!!!!!!

excel for python3.7

2022-09-22 18:28

1 Answers

] It's missing. There is still a grammar error, so try that part yourself.

list = [[0.1,0.2,0.3], [0.1,0.3,0.6], [0.2,1.4,0.3], [1.6,1.4,1.5,1,1,1,1] # is missing 

Additionally, __len___ functions that start with this dunder are not intended to be called directly, but rather to be called as callbacks.

Please revise it as below.

len(initSet)

Of course, calling the len function (not the actual function) calls the _len___, but the two can produce completely different results.

Keep in mind that special methods do not call directly except in unusual cases.


2022-09-22 18:28

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.