【问题标题】:how to insert header or footer to a word document using c++ automation如何使用 C++ 自动化在 Word 文档中插入页眉或页脚
【发布时间】: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


【解决方案1】:

你的 C++ 在哪里相​​当于

Headers[WdHeaderFooterIndex.wdHeaderFooterPrimary]

类似

Hf.GetItem(wdHeaderFooterPrimary).GetRange();

【讨论】:

    【解决方案2】:

    对于仍在寻找答案的人:

    HeadersFooters Hfs = firstSec.GetHeaders();
    HeaderFooter Hf = Hfs.Item(1);
    Range MyRange = Hf.GetRange();
    MyRange.SetText( L"salam" );
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-03-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-03-09
      • 2011-03-19
      • 2010-09-26
      相关资源
      最近更新 更多