我试着把ascii转换成十六进制值。但我的剧本有时奏效,有时行不通。我想知道为什么。代码如下:
ascii码=B13515068
for i in range(50): #In excel I have 50 row
ascii_ch = sheet['C%s'%(i+2)].value #after C2, convert hex
ascii_to_hex= "".join("{:02x}".format(ord(c)) for c in ascii_ch )
sheet['I%s'%(i+2)] = ascii_to_hex
wb.save('a.xlsx')
我想要ascii_to_hex=423133353135303638
看起来并不是所有的单元格都有与之相关的值。当单元格没有值时,
ascii_ch = sheet['C%s'%(i+2)].value
会将ascii_ch
设置为None
。在下一行中,迭代ascii_ch
。但是在None
上迭代没有任何意义!在你可能要检查一下,像这样:
相关问题 更多 >
编程相关推荐