I want to implicitly close workbook on class instance destruction. xlsxwriter.workbook.py method says to do it explicitly and then it works. But then at the end of each Excel file creation script I have to add extra line for closing Workbook. Is there a way to make it auto-closing?
import pandas as pd
import xlsxwriter
class ExcelFile():
def __init__(self, file_name):
self.writer = pd.ExcelWriter(file_name, engine='xlsxwriter')
self.workbook = self.writer.book
def __del__(self):
self.workbook.close()
print('del')
script:
e = ExcelFile('test.xlsx')
# e.workbook.close() <--This works but I don't want this line