How to open a table in QTableWidget using the xlrd module?
1 answer
Like that:
Read the data:
import xlrd book = xlrd.open_workbook('book.xlsx') sheet = book.sheets() [1] data = [[sheet.cell_value(r,c) for c in range (sheet.ncols)]for r in range(sheet.nrows)] Adding data to a QTableWidget :
from PySide import QtGui app = QtGui.QApplication([]) mytable = QtGui.QTableWidget() # если нет заголовков, то следующие три строки можно удалить headers = data[0] data = data[1:] mytable.setHorizontalHeaderLabels(headers) for row, columnvalues in enumerate(data): for column, value in enumerate(columnvalues): item = QtGui.QTableWidgetItem(str(value)) mytable.setItem(row, column, item) - Thanks I will try - Dr.robot
|