使用openpyxl(python)在列中多行写入十六进制二进制转换

使用openpyxl(python)在列中多行写入十六进制二进制转换,python,excel,binary,hex,openpyxl,Python,Excel,Binary,Hex,Openpyxl,我的目标是将单元格的值(对于列E中特定范围内的每一行)从十六进制转换为BIN,并将每一行的BIN写入列N中。转换本身以及将BIN值写入某个单元格都没有问题。但是我对行的迭代有问题。只是想澄清一下:我希望E1中的十六进制代码打印在N1中的BIN代码中,E2中的值打印在N2中,依此类推 A B C D E F G H I J K L M N 90 ‭10010000‬ 8A

我的目标是将单元格的值(对于列E中特定范围内的每一行)从十六进制转换为BIN,并将每一行的BIN写入列N中。转换本身以及将BIN值写入某个单元格都没有问题。但是我对行的迭代有问题。只是想澄清一下:我希望E1中的十六进制代码打印在N1中的BIN代码中,E2中的值打印在N2中,依此类推

A  B  C D  E  F  G  H  I  J  K  L  M  N
           90                         ‭10010000‬
           8A                         ‭10001010‬
           ..                         ....
这是我的密码:

theFile = openpyxl.load_workbook('T013.xlsx')
allSheetNames = theFile.sheetnames 
print("All sheet names {} " .format(theFile.sheetnames)) 
sheet = theFile.active

for row in sheet.iter_rows(min_row=1, max_row=1210,values_only = True): 
    for cell in sheet["E"]: 
        if cell.value is None:
            print("Blank")
        else: 
            inputHEX = str(cell.value) 
            res = "{0:08b}".format(int(inputHEX,16))
            print(res)
            for x in sheet["N1:N1210"]:
                sheet.cell(row=x, column=1).value = str(res) #same error as with res without str 
theFile.save("C:\\Users\\...\\Adapted_T013.xlsx") 
我得到的错误是:

C:\Users\...\Desktop\Practical Part\CAN Python>python ExcelDecode.py
All sheet names ['T013']
Blank
11100001
Traceback (most recent call last):
  File "ExcelDecode.py", line 42, in <module>
    sheet.cell(row=x, column=1).value = res
  File "C:\Users\...\AppData\Local\Programs\Python\Python38-32\lib\site-packages\openpyxl-3.0.3-py3.8.egg\openpyxl\worksheet\worksheet.py", line 235, in cell
TypeError: '<' not supported between instances of 'tuple' and 'int'`
C:\Users\…\Desktop\Practical Part\CAN Python>Python ExcelDecode.py
所有图纸名称['T013']
空白的
11100001
回溯(最近一次呼叫最后一次):
文件“ExcelDecode.py”,第42行,在
sheet.cell(行=x,列=1)。value=res
文件“C:\Users\…\AppData\Local\Programs\Python38-32\lib\site packages\openpyxl-3.0.3-py3.8.egg\openpyxl\worksheet\worksheet.py”,第235行,在单元格中

类型错误:'正确的实现:

theFile = openpyxl.load_workbook('T013.xlsx')
allSheetNames = theFile.sheetnames 
print("All sheet names {} " .format(theFile.sheetnames)) 
sheet = theFile.active

for row in sheet.iter_rows(min_row=1, max_row=1210,values_only = True): 
    for cell in sheet["E"]:
        if cell.value is not None:
            inputHEX = str(cell.value)
            res = "{0:08b}".format(int(inputHEX,16))
            sheet.cell(row=cell.row, column=14).value = res
    break
theFile.save("C:\\Users\\..\\Adapted_T013.xlsx") 

请包括完整的traceback@CharlieClark:谢谢你的评论!我已经包括了回溯。这有助于理解问题吗?@Nezuko
TypeError:“@stovfl:非常感谢您的解释和提示!我能得到我想要的。非常高兴:-)谢谢!