diff --git a/writeExcel.py b/writeExcel.py index b4fbd03d60e3271a314e3234047d82bba8eb5143..662dd0d9b7b7b139ef5951af4e9eac8e1d1257bb 100644 --- a/writeExcel.py +++ b/writeExcel.py @@ -21,7 +21,16 @@ class ExcelWriter: When inserting an entry, it might be a test being re-run. In that case, the row containing that test needs to be updated, as opposed to appending the entry to the end of the file. + This method finds that row, returning the row number, + or -1 in the case where that test is not in the report yet. """ + for cell in self.ws["A"]: + if cell.value is None: + return -1 + elif cell.value == id: + print("MATCH with id {} at row {}".format(id, cell.row)) + return cell.row + return -1 def getLastRow(self): for cell in self.ws["A"]: @@ -30,10 +39,18 @@ class ExcelWriter: return cell.row + 1 def writeTestEntry(self, testEntry): + existingEntryRow = self.getEntryWithId(testEntry.id) lastRow = self.getLastRow() + # Use the above two values to pick a row + entryRow = existingEntryRow if existingEntryRow != -1 else lastRow + + # Pick a cell color based on test outcome cellCol = ExcelWriter.PASS_COL if testEntry.result == "PASS" else ExcelWriter.FAIL_COL + + # Test entry as a list entryVals = testEntry.asList() - for col, cellValue in zip(self.ws.iter_cols(min_row=lastRow, max_col=len(entryVals), max_row=lastRow), entryVals): + + for col, cellValue in zip(self.ws.iter_cols(min_row=entryRow, max_col=len(entryVals), max_row=entryRow), entryVals): for cell in col: cell.value = cellValue cell.fill = PatternFill("solid", fgColor=cellCol)# cellCol