Report_Generate_Server/tools/Spiretool.py

20 lines
584 B
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

from spire.doc import *
from spire.doc.common import *
# 加载第一个文档
doc1 = Document()
doc1.LoadFromFile("./muban/jingfeng_1.docx")
# 加载第二个文档
doc2 = Document()
doc2.LoadFromFile("./muban/jf_hengxiang.doc")
# 遍历 doc2 的所有节(使用 GetSections()
for i in range(doc2.Sections.Count):
section = doc2.Sections.get_Item(i) # 使用 GetItem 获取 Section
doc1.Sections.Add(section.Clone()) # 克隆并添加到 doc1
# 保存合并后的文档
doc1.SaveToFile("./output/MergedDocument.docx", FileFormat.Docx2019)
doc1.Close()
doc2.Close()