简体   繁体   中英

Filling Excel cells using openpyxl

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')

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 ).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM