0
votes

in my new department i have to code with python and openpyxl. I have to fill cells of an excel sheet with test runs and the result(passed/failed). This is all i got so far. I am not getting any errors but the sheet is still empty.. Any help would be nice. Thanks in advance.

def create_report(self, root, now):
    tests = (
        ['Discover DTC time', 'failed'],
        ['Drucksensor_DTC_Startup', 'failed'],
        ['Drucksensor_DTC_Runtime', 'passed'],
    )

    wb = xl.Workbook()
    ws = wb.active
    ws.title = 'ExcelSummaryReport.xlsx'

    row = 1
    col = 0

    for i in range(row, ws.max_row):
        for j in range(col, ws.max_col):
            ws.cell(row=i + 1, col=j).value = tests[i]

    wb.save('ExcelSummaryReport.xlsx')
1
What does this have to do with pycharm? - Scott Hunter
the ide i'm using is pycharm - d-hug
ws.max_row and ws.max_col really ought not be used like this. Just loop over your test results and ws.append() - Charlie Clark
so how do i have to use ws.append()? how has the loop going to look like? - d-hug

1 Answers

0
votes

If you are creating a new worksheet, it doesn't have any rows or columns, so max_row and max_col are 0, and your loop does nothing. How many rows/columns to fill looks like it should be determined by the data (tests).