我有以下代码:
ws = wb.worksheets[1]
print(ws)
with open('out.txt', 'r+') as data:
reader = csv.reader(data, delimiter='\t')
for row in reader:
print(row)
ws.append(row)
wb.save('test.xlsx')
默认情况下,它会从A0开始写入xlsx文件
是否有更方便的方法开始添加数据(例如从C2开始)?
还是只有xxx.cell(row=xx , column=yy ).value=zz
?
i = 2
j = 3
with open('out.txt', 'r+') as data:
reader = list(csv.reader(data, delimiter='\t'))
for row in reader:
for element in row:
ws.cell(row=i, column=j).value = element
j += 1
j = 3
i += 1
答案 0 :(得分:0)
只需用None
s填充行
ws.append([]) # move to row 2
for row in reader:
row = (None)*2 + row
ws.append(row)