首页 文章

在内存文件中压缩excel电子表格

提问于
浏览
0

我试图按照下面的代码压缩openpyxl创建的excel电子表格以及其他文件但是我收到以下错误,任何帮助

Error:

回溯(最近一次调用最后一次):文件“C:\ Python27 \ lib \ site-packages \ cherrypy_cprequest.py”,第670行,在响应中响应.body = self.handler()文件“C:\ Python27 \ lib \ site-packages \ cherrypy \ lib \ encoding.py“,第217行,在调用self.body = self.oldhandler(* args,** kwargs)文件”C:\ Python27 \ lib \ site-packages \ cherrypy_cpdispatch.py“ ,第60行,在调用返回self.callable(* self.args,** self.kwargs)文件“example.py”,第2282行,在RPC_submit中wb.save(iostream4)文件“C:\ Python27 \ lib \ site -packages \ openpyxl \ workbook \ workbook.py“,第345行,保存save_workbook(self,filename)文件”C:\ Python27 \ lib \ site-packages \ openpyxl \ writer \ excel.py“,第266行,在save_workbook中writer.save(filename)文件“C:\ Python27 \ lib \ site-packages \ openpyxl \ writer \ excel.py”,第248行,保存self.write_data()文件“C:\ Python27 \ lib \ site-packages \ openpyxl \ writer \ excel.py“,第81行,在write_data self._write_worksheets()文件”C:\ Python27 \ lib \ site-packages \ openpyxl \ writer \ excel.py“,第211行,在_write_worksheets self中._write_comment(ws)文件“C:\ Python27 \ lib \ site-packages \ openpyxl \ writer \ excel.py”,第181行,_write_comment vml = fromstring(self.workbook.vba_archive.read(ws.legacy_drawing))AttributeError :'NoneType'对象没有属性'read'

Code:

file_name4 = 'SP' + kwargs['sp'] + '-'+ kwargs['WO'] + ' ' + kwargs['site'] + 'TE - ' + 'Asset Distribution' +'.xlsx'
file_path = path + "\\" + file_name4
wb.save(file_path)

iostream4 = StringIO.StringIO()
wb.save(iostream4)

zip_output = StringIO.StringIO()
file = zipfile.ZipFile(zip_output, "w")

file.writestr(file_name0, iostream.getvalue())

file.writestr(file_name4, iostream4.getvalue())

file.close()

cherrypy.response.headers['Content-Type'] = 'application/zip'
cherrypy.response.headers['Content-Disposition'] = (
 'attachment; filename={fname}.zip'.format(
     fname='SP' + kwargs['sp'] + '-'+ kwargs['WO'] + ' ' + kwargs['site'] + ' - ' + 'Request for PC Documentation'  +'.zip'
 )
 )
return zip_output.getvalue()

1 回答

相关问题