Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/342.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在每次运行代码时以递增的行将输入从python传输到excel_Python - Fatal编程技术网

如何在每次运行代码时以递增的行将输入从python传输到excel

如何在每次运行代码时以递增的行将输入从python传输到excel,python,Python,我是python的初学者,有一个问题。 我编写这段代码的目的是让它接受Python中的输入,并以增加行的方式将它们传输到Excel中。 例如,第一个输入转到A1,下一次运行的下一个输入转到A2,以此类推 wb = openpyxl.load_workbook('name.xlsx') ws = wb.active yourname=input("Please enter your name here: ") i=0 while True: ws['A'+i] = yourname

我是python的初学者,有一个问题。 我编写这段代码的目的是让它接受Python中的输入,并以增加行的方式将它们传输到Excel中。 例如,第一个输入转到A1,下一次运行的下一个输入转到A2,以此类推

wb = openpyxl.load_workbook('name.xlsx')
ws = wb.active

yourname=input("Please enter your name here: ")
i=0
while True:
    ws['A'+i] = yourname
    i += 1
    break
wb.save('name.xlsx')

谢谢。

ws['A'+i]=yourname这可能不适用于openpyxl,您可以将其用于xlwings,而对于openpyxl,则使用此ws.cell(rownum,colnum).value=data

import openpyxl as op
wb = op.load_workbook('name.xlsx')
ws = wb.active

i=1
# i = 1 because Excel row starts with 1 
while True:
    # enter exit when you're done
    yourname = input("Please enter your name here: ")
    if yourname == 'exit':
        break

    else:
        # i is for row count and 1 is for column column, you can change these as per your need

        ws.cell(i,1).value= yourname
        i= i+1

wb.save('name.xlsx')
这应该有助于你开始:在旁注上——试着看看vb.Net,它是一种更适合你的技术……阅读