python2.7使用xlsxwriter创建excel ,不关闭xlsxwriter对象,会报错:
Exception Exception: Exception('Exception caught in workbook destructor. Explicit close() may be required for workbook.',) in <bound method Workbook.__del__ of <xlsxwriter.workbook.Workbook object at 0x0000000002215400>> ignored
脚本如下:
#coding=utf-8 import xlsxwriter #创建excel文件 workbook = xlsxwriter.Workbook('test.xlsx') worksheet = workbook.add_worksheet('test')
报错信息如下:
查资料才知道 一定要把xlsxwriter对象给关闭了,加上workbook.close()后,完美解决 文件创建成功,如下截图:
注:python3.6版本没此问题,不用workbook.close(),也可以执行成功!