【发布时间】:2017-02-12 14:15:04
【问题描述】:
在我的新部门,我必须使用 python 和 openpyxl 进行编码。我必须用测试运行和结果(通过/失败)填充 excel 表的单元格。 这就是我到目前为止所得到的。我没有收到任何错误,但工作表仍然是空的。任何帮助都会很好。提前致谢。
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')
【问题讨论】:
-
这和pycharm有什么关系?
-
我用的ide是pycharm
-
ws.max_row和ws.max_col真的不应该这样使用。只需遍历您的测试结果和ws.append() -
那么我必须如何使用 ws.append()?循环会是什么样子?
标签: python excel pycharm openpyxl