简体   繁体   English

PyQt5 中未显示某些 tableWidget 单元格

[英]Some tableWidget cells aren't showing in PyQt5

So I am creating a tableWidget to track sales in PyQt5.所以我正在创建一个 tableWidget 来跟踪 PyQt5 的销售情况。

TableWidget 的图像

The table gets data from an excel sheet.该表从 excel 表中获取数据。

The problem is that the first two items is showing but the other ones are not ( as you see in the picture )问题是前两个项目正在显示,但其他项目没有(如图所示)

Here's the code I wrote:这是我写的代码:

def refreshTable():
    ui.tableWidget.setRowCount(0)
    for j in range(1,ws2.max_row+1):
        ui.tableWidget.insertRow(ui.tableWidget.rowCount())
        ui.tableWidget.setItem(j-1 , 0, QtWidgets.QTableWidgetItem(ws2["A"+str(j)].value))
        ui.tableWidget.setItem(j-1 , 1, QtWidgets.QTableWidgetItem(ws2["B"+str(j)].value))
        ui.tableWidget.setItem(j-1 , 2, QtWidgets.QTableWidgetItem(ws2["C"+str(j)].value))
        ui.tableWidget.setItem(j-1 , 3, QtWidgets.QTableWidgetItem(ws2["D"+str(j)].value))

Note: the excel sheet (ws2) is contains all the necessary information so there is no problem in it.注意:excel 表 (ws2) 包含所有必要信息,因此没有问题。 Note 2: You may need to know that I'm using openpyxl to read/write in the excel sheet.注意 2:您可能需要知道我正在使用 openpyxl 在 excel 表中进行读/写。

I fixed the problem !我解决了这个问题!

I just put ws2["A"+str(j)].value inside str()我只是将ws2["A"+str(j)].value放入str()

def refreshTable():
    ui.tableWidget.setRowCount(0)
    for j in range(1,ws2.max_row+1):
        ui.tableWidget.insertRow(ui.tableWidget.rowCount())
        ui.tableWidget.setItem(j-1 , 0, QtWidgets.QTableWidgetItem(str(ws2["A"+str(j)].value)))
        ui.tableWidget.setItem(j-1 , 1, QtWidgets.QTableWidgetItem(str(ws2["B"+str(j)].value)))
        ui.tableWidget.setItem(j-1 , 2, QtWidgets.QTableWidgetItem(str(ws2["C"+str(j)].value)))
        ui.tableWidget.setItem(j-1 , 3, QtWidgets.QTableWidgetItem(str(ws2["D"+str(j)].value)))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM