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
嗨,我是一个初学者,当我运行这段代码时,它正常运行,并在excel表的前5行中从'a'写入值,但我想创建一个使用嵌套循环的代码,像这样
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
此代码没有在excel表格中写入上述数据。请帮帮我
在python intendation很重要,所以尝试:
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
: https://www.geeksforgeeks.org/indentation-in-python/
似乎您的for
循环从第二个代码是不正确的选项卡,并在with
之外。