For this I have converted my csv file to xlsx file as xlrd does not take csv. Download these: pip install pandas pip install openpyxl
read_file = pd.read_csv(r"path where your csv file is stored/Details.csv")
read_file.to_excel(r"path where you want to store xlsx/Details.xlsx", index=None, header=True)
self.anomaly_details = xlrd.open_workbook("./appData/Details.xlsx")
self.sheet = self.anomaly_details.sheet_by_index(0)
self.data = [
[self.sheet.cell_value(r, c) for c in range(self.sheet.ncols)]
for r in range(self.sheet.nrows)
]
# print(self.data)
self.alarm_tableWidget.setColumnCount(4)
self.alarm_tableWidget.setRowCount(
self.sheet.nrows - 1
) # same no.of rows as of csv file
for row, columnvalues in enumerate(self.data):
for column, value in enumerate(columnvalues):
self.item = QtWidgets.QTableWidgetItem(
str(value)
) # str is to also display the integer values
self.alarm_tableWidget.setItem(row - 1, column, self.item)
# to set the elements read only
self.item.setFlags(QtCore.Qt.ItemIsEnabled)