本文我们将详细介绍如何使用spire.doc高效的复制word文档的页眉或页脚(包括文本和图形),并插入到其他word文档。
c#
//加载源文档
document doc1 = new document();
doc1.loadfromfile("test1.docx");
//获取第一个section的页眉
headerfooter header = doc1.sections[0].headersfooters.header;
//加载新文档
document doc2 = new document("test2.docx");
foreach (section section in doc2.sections)
{
//将页眉中的对象进行复制,并插入到新文档中
foreach (documentobject obj in header.childobjects)
{
section.headersfooters.header.childobjects.add(obj.clone());
}
}
vb.net
'加载源文档
dim doc1 as document = new document
doc1.loadfromfile("test1.docx")
'获取第一个section的页眉
dim header as headerfooter = doc1.sections(0).headersfooters.header
'加载新文档
dim doc2 as document = new document("test2.docx")
for each section as section in doc2.sections
'将页眉中的对象进行复制,并插入到新文档中
for each obj as documentobject in header.childobjects
section.headersfooters.header.childobjects.add(obj.clone)
next
next
源文档:
结果文档: