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

时间:2017-11-27 05:30:47

标签: python excel

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

错误:

  

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

代码:

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()

0 个答案:

没有答案