gpt4 book ai didi

python - 异常 ('Exception caught in workbook destructor. Explicit close() may be required for workbook.'

转载 作者:行者123 更新时间:2023-11-28 16:33:05 31 4
gpt4 key购买 nike

我在 Oracle Linux 6.6 中运行我的 Python 程序时遇到以下异常。我使用的是 Python 2.6 版。

Exception('Exception caught in workbook destructor. Explicit close() may be required for workbook.'

我的代码是:

import warnings
warnings.filterwarnings("ignore")
import mysql.connector
import smtplib
import math
#from xlrd import open_workbook
import numbers, string
import xlsxwriter
import string
import time
import base64
import subprocess
import os
import sys
import commands
import itertools
#import xlwt
import datetime as dt
import email.mime.application
from datetime import datetime
from datetime import datetime,timedelta, date
from email import Encoders
from tempfile import TemporaryFile
#from xlwt import Workbook, XFStyle, Borders, Pattern, Font
from email.MIMEMultipart import MIMEMultipart
from email.mime.audio import MIMEAudio
from email.mime.base import MIMEBase
from email.mime.image import MIMEImage
from email.MIMEText import MIMEText
from email.Utils import formatdate
import datetime
from xlsxwriter.workbook import Workbook
from xlsxwriter import Workbook

curtme = datetime.datetime.strftime(datetime.datetime.now(), '%Y-%m-%d_%H:%M:%S')
workbook = xlsxwriter.Workbook('/Export/Report_'+curtme+'.xlsx')
worksheet = workbook.add_worksheet()
completed_fmt = workbook.add_format({'bold': True, 'border': 6,'align': 'center','valign': 'vcenter','bg_color': 'yellow','font_size':'12', 'font_name':'Calibri'})
worksheet.set_column(0,9,36)
worksheet.merge_range('A2:C6',None, None)
worksheet.merge_range('A2:C6',None, None)
cellformat = workbook.add_format({'bold': True, 'border': 6,'align': 'center','valign': 'vcenter','font_size':'16', 'font_name':'Calibri'})
cellfmt = workbook.add_format({'bold': False, 'border': 6,'align': 'center','valign': 'vcenter','font_size':'12', 'font_name':'Calibri'})
worksheet.insert_image('A1', 'Image/logo.jpg')
worksheet.merge_range('B1:C6', "Report", cellformat)
rowx = 6
for colx, value in enumerate(headings):
worksheet.write(rowx, colx, value, completed_fmt)
i=1
for i, row in enumerate(myresult):
for j, col in enumerate(row):
worksheet.write(i+7, j, col,cellfmt)
workbook.close()
db.close()

最佳答案

异常说明 close() 可能 是必需的。这是为了捕获隐式关闭不充分的 xlsxwriter 异常。

因为 close() 已经包含在您的程序中,这不是异常的来源。

实际错误将在堆栈跟踪中显示在它之上。一些潜在的问题:

  1. 缩进错误。
  2. headings 未定义。
  3. myresult 未定义。

关于python - 异常 ('Exception caught in workbook destructor. Explicit close() may be required for workbook.',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29971773/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com