根据标题字符串和所选行获取单元格值

根据标题字符串和所选行获取单元格值,第1张

根据标题字符串和所选行获取单元格值

如果这样做,您将得到:“分配前已引用局部变量’matchcol’”

要解决此问题,您应该在if循环中返回单元格:

#===================================================================# given a tablewidget which has a selected row...# return the column value in the same row which corresponds to a given column name# fyi: columnname is case sensitive#===================================================================def getsamerowcell(widget,columnname):    row = widget.currentItem().row()    #col = widget.currentItem().column()    #loop through headers and find column number for given column name    headercount = widget.columnCount()    for x in range(0,headercount,1):        headertext = widget.horizontalHeaderItem(x).text()        if columnname == headertext: cell = widget.item(row, x).text()   # get cell at row, col return cell


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5640083.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-16
下一篇 2022-12-16

发表评论

登录后才能评论

评论列表(0条)

保存