51Testing软件测试论坛

标题: 使用openpyxl操作excel [打印本页]

作者: 芒果go    时间: 2016-11-2 10:17
标题: 使用openpyxl操作excel
在使用set_value_explicit函数向表中写入数据时,提示AttributeError: 'Cell' object has no attribute 'set_value_explicit',为甚么啦,如何写入数据到已有的excel中啦??
作者: 菜鸟@大虾    时间: 2016-11-2 13:49
定位到单元格,直接赋值即可,例子如下 请参考:


#在Excel中记录结果
#we should keep the directory of project
#If we do not,we will accur some trouble
def WriteExcel(result, locator,sheetname):
    book = load_workbook(autocase)
    sheet = book.get_sheet_by_name(sheetname)
    if result == True:
        sheet.cell(locator).value = 'Pass'
    elif result == False:
        sheet.cell(locator).value = 'Fail'

    book.save(autocase)






欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/) Powered by Discuz! X3.2