【发布时间】:2012-05-25 05:35:29
【问题描述】:
我想使用 word 自动化在 word 文档中插入页眉或页脚。
_document ocDoc;
Sections DocSections = Sections(ocDoc.GetSections());
section firstSec = DocSections.Item( 1 );
HeaderFooter Hf = firstSec.GetHeaders();
Range MyRange = Hf.GetRange();
MyRange.SetText( L"salam" );
但代码部分是“Range MyRange = Hf.GetRange();”失败的, 如何使用 c++ 在 word 文档中插入页眉或页脚?
c# 中的以下代码可以正常工作:
_document ocDoc;
oDoc.Sections[1].Headers[WdHeaderFooterIndex.wdHeaderFooterPrimary].Range.Text = "My Header";
【问题讨论】:
-
当你说它失败了——它到底做了什么?抛出异常,崩溃,返回NULL,还有什么?
-
这看起来很棒。我还在使用 OLEMethods,你能给我一些 _document 和 Section 类的代码吗?
标签: c++ ms-word automation get-headers