Skip to main content
naming
Source Link
Vince
  • 20.3k
  • 16
  • 48
  • 65

For this I have converted my csvCSV file to xlsxXLSX file as xlrdxlrd does not take csvCSV. 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)

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)

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)
deleted 71 characters in body
Source Link
Kadir Şahbaz
  • 78k
  • 57
  • 257
  • 404

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

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)

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)

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)
Source Link

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)