Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/25.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_Excel_Input_Openpyxl - Fatal编程技术网

Python 将文本用户输入写入excel

Python 将文本用户输入写入excel,python,excel,input,openpyxl,Python,Excel,Input,Openpyxl,我正在使用openpyxl。用户被要求输入许多数字,这些数字可以很好地写入excel,但我需要更改代码,使其也可以将文本输入写入excel。我需要改变什么以及如何改变 for rowNum in range(1, 5): name = sheet.cell(row=rowNum, column=1).value if name in Dictionary1: sheet.cell(row=rowNum, column=2).value = Dictionary1[name] 我认为“值

我正在使用openpyxl。用户被要求输入许多数字,这些数字可以很好地写入excel,但我需要更改代码,使其也可以将文本输入写入excel。我需要改变什么以及如何改变

for rowNum in range(1, 5):
name = sheet.cell(row=rowNum, column=1).value
if name in Dictionary1:
    sheet.cell(row=rowNum, column=2).value = Dictionary1[name]

我认为“值”部分是问题所在,需要更改文本?

这应该是您想要的:

for rowNum in range(1, 5):
    for row in sheet.iter_rows(min_row=rowNum, max_row=rowNum, max_col=1):
        for cell in row:
            name = cell.value
            if name in Dictionary1:
                cell.offset(column=1).value = Dictionary1[name]

真正的问题是什么?openpyxl不关心您是添加文本还是数字。