|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本人用xlrd读取excel表的数据,同时将读取的数据做个减法,代码如下:
row_list=[ ]
for i in range(3, nrows):
cell=table.cell(i, 46).value-20
row_list.append(cell)
self.textEdit.append(str(cell))
QMessageBox.about(self,'结果',str(row_list))
几个疑问:
1、cell=table.cell(i, 46).value-20运行后报错,报错信息:unsupported operand type(s) for-:'str' and 'int',针对这个错误,我修改为:
cell=float(table.cell(i, 46).value)-20,运行后依然报错:could not convert string to float,请问问题出在哪里呢?
2、self.textEdit.append(str(cell))只能导入字符型的吗,我写成self.textEdit.append(cell)也会报错:append(self,str):argument 1 has unexpected type 'float'?
3、QMessageBox.about也只能显示str吗?
请教大家!
啊,一开始看错问题了。
第一个问题呢,你要获取的单元格数据“不纯洁”,包含了除数字字符串以外的字符串,若果确定没有英文字母,你可以试下float(table.cell(i,46).value.strip()) - 20
第二个问题,self.textEdit.append()方法应该是只能接收str参数,详细的你得看下官方文档
|
|