1

I've programmed a GUI for, among other things, reading an excel data and showing the values. I'm using xlrd for this. I've tried it with for loop through a constant number of rows and columns (I know how big the data is) and it works how it should. I'm using PyCharm for it.

Next step should be a while loop, which can read any data, doesn't matter how big it is. For this reason I've come to an idea: - I'm checking if there is any blank row or column - If there's more than 10 blank rows or columns after each other, the programm should stop doing the while loop

The problem: my method setDatei() is opening a file and loading the values of every cell at the same time. It works for the first case only if I set as counter the last row/column of this file. If it's only 1 number above, the program will return: "Process finished with exit code -1073740791 (0xC0000409)". The same happens trying to do the second case with while loop.

I've tried to understand this: Process finished with exit code -1073741571 or that: How to overcome Stack Size issue with Visual Studio (running C codes with big array) But I think I haven't just understood it. It should work on every pc, not only on mine, so changing any pc settings is not wishable.

Case 1: works

def setDatei(self): #Programmauswahl
    fileName, _ = QtWidgets.QFileDialog.getOpenFileName(None, "Waehle das Programm aus", "",
                                                        "Excel Files *.xlsx *.xls")  # Frage nach Datei
    if fileName:  # Wenn der Benutzer eine Datei gibt
        print(fileName)
        self.setLine.setText(fileName) # zeigt den Dateinamen in der Leiste oben links
        ####Öffnet die Datei und lädt die Werte
        workbook = xlrd.open_workbook(fileName)
        worksheet = workbook.sheet_by_index(0)
        # 16 Zeilen, 11 Spalten
        n = 0
        m = 0
        for i in range(0, 16):  # for-Schleife, um alle Zellen auszulesen und übertragen
            m = 0
            a = str(worksheet.cell(n, m).value)
            for i in range(0, 11):
                a = str(worksheet.cell(n, m).value)
                self.tableWidget.setItem(n, m, QtWidgets.QTableWidgetItem(a))
                m = m + 1
            n = n + 1

Case 2: doesn't work

def setDatei(self): #Programmauswahl
    fileName, _ = QtWidgets.QFileDialog.getOpenFileName(None, "Waehle das Programm aus", "",
                                                        "Excel Files *.xlsx *.xls")  # Frage nach Datei
    if fileName:  # Wenn der Benutzer eine Datei gibt
        print(fileName)
        self.setLine.setText(fileName) # zeigt den Dateinamen in der Leiste oben links
        ####Öffnet die Datei und lädt die Werte
        workbook = xlrd.open_workbook(fileName)
        worksheet = workbook.sheet_by_index(0)


        lineThreshold = 10
        columnThreshold = 10

        row = 0
        lineEmptyCounter = 0
        while True:
            col = 0
            columnEmptyCounter = 0
            lineEmpty = True


            while True:
                value = str(worksheet.cell(row, col).value)
                if value is None:
                    columnEmptyCounter += 1
                else:
                    lineEmpty = False
                    columnEmptyCounter = 0
                    self.tableWidget.setItem(row, col, QtWidgets.QTableWidgetItem(value))

                if columnEmptyCounter >= columnThreshold:
                    break
                else:
                    col = col + 1

            if lineEmpty:
                lineEmptyCounter += 1
            else:
                lineEmptyCounter = 0
            if lineEmptyCounter >= lineThreshold:
                break
            else:
                row = row+1

Process finished with exit code -1073740791 (0xC0000409). The programm closes without any information. I've no idea where to start. If you need further details, just let me know.

MKey69
  • 63
  • 5
  • Potentially relevant answer: https://stackoverflow.com/questions/50562192/process-finished-with-exit-code-1073740791-0xc0000409-pycharm-error – beroe May 20 '19 at 21:32
  • Well, for the immediate problem of writing a loop to read all the data, use the `nrows` property of the worksheet object. But there are several more improvements you can make. You'll want to explore the xlrd documentation further, or better yet, look for the [Python Excel tutorial PDF](https://github.com/python-excel/tutorial/blob/master/python-excel.pdf). (I say "look for" because I don't know if that is its permanent home. If that link dies, you'll have to Google for copies floating around the Internet.) – John Y May 20 '19 at 21:37
  • What I did was taking the case 1 and changing the amount of rows/columns which was 16 and 11, to worksheet.nrows and worksheet.ncols. Now it works with every file. Thank you very much for bringing me to it :) – MKey69 May 20 '19 at 22:36

0 Answers0