如果这样做,您将得到:“分配前已引用局部变量’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
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)