20 lines
584 B
Python
20 lines
584 B
Python
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() |