如何在python中将docx.document.document对象插入到zip文件对象中?



我动态创建word文档,我想将它们插入到可以在网页中下载的同一zip文件夹对象中,但是如何将word文档对象变量插入python中的zip文件夹对象(请注意,这不是已经保存在我的桌面中的word文档(?

谢谢你的帮助。

我使用write方法与io.bytesIO 流结合使用,将 word 文件(及其格式(添加到 ZIP 存档对象:

f = io.BytesIO()
zipObj = ZipFile(f, ‘a’)
for File_name in Obj_Attr_List:
Contrat_word = Create_Word_Contract(File_name)
Contrat_word.save(File_name + ‘.docx’)
zipObj.write(File_name + ‘.docx’)
zipObj.close()
response = HttpResponse(f.getvalue(),content_type=‘application/zip’)
response[‘Content-Disposition’] = ‘attachment; filename=ZipArchName.zip’
return response

PJ

相关内容

最新更新