使用python-docx中的Composer时候怎么按照每个文档的方向指定横向和纵向呢,比如要合并1, 2, 3, 1,2纵向,3横向,
现在的效果是合并后的文档要么全是横向,要么全是纵向。
要的效果合并后端文档应该保持不变,1,2部分为纵向,3部分为横向。
用代码块功能插入代码,请勿粘贴截图
list = [
{'path': '1.docx','orientation': 0},
{'path': '2.docx','orientation': 0},
{'path': '3.docx','orientation': 1}
]
new_document = Document()
composer = Composer(new_document)
for item in list:
doc = Document(item.path)
sections = doc.sections
# 这样设置好像没效果
for section in sections:
new_width = 0
new_height = 0
if item.orientation == 1:
new_width, new_height = section.page_height,section.page_width
section.orientation = WD_ORIENTATION.LANDSCAPE #LANDSCAPE / PORTRAIT
else:
new_width, new_height = section.page_width,section.page_height
section.orientation = WD_ORIENTATION.PORTRAIT #LANDSCAPE / PORTRAIT
section.page_width = new_width
section.page_height = new_height
doc.add_page_break()
composer.append(doc)
composer.save('new_doc.docx')