如何在页眉或页脚中添加ContentContol? [英] How to add ContentContol in header or footer?

查看:97
本文介绍了如何在页眉或页脚中添加ContentContol?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,

我在文档的页眉和页脚中有一些内容控件(Combo,TextEdit)的文档。我需要从代码中围绕这些现有控件添加GroupContentControls。

I have a document with some content controls (Combo, TextEdit) inside header and footer of the document. I need from code to add GroupContentControls around these existing controls.

第一个问题是,即使我能够在文档的主体中实现我的目标:

First problem is that even I'm able to achieve my goal in the document's main body:

var gccRange = _vstoDoc.Range(contnCtl.Range.Start - 1, contnCtl.Range.End + 1);
gccRange.Select();
var gcc = _vstoDoc.Controls.AddGroupContentControl(gccRange, "GroupContentControlAnchor_" + Guid.NewGuid());
gcc.LockContentControl = true;

只要有gccRange.Select()就可以使用上面的代码。任何克服Select()操作必要性的尝试都失败了(总是抛出异常)。不应该AddgroupContentControl的第一个参数使Select()调用过时吗?

The code above works as long as there is gccRange.Select() in place. Any attempts to overcome neccessity of Select() operation have failed (always exception is thrown). Shouldn't the first argument of AddgroupContentControl make the Select() call obsolete?

总而言之 - 有没有办法在没有选择的情况下做我想做的事情?选择看起来很难看(用户可以看到它),它更慢。

All in all - is there a way to do what I want to do without selection? Selection looks ugly (user can see it) an it is slower.

第二个问题是做同样的事情,但是对于页眉和页脚中的控件。经过几个小时的尝试,我想出了以下代码。代码有效,但在所有方面都比上一个更加丑陋。

Second problem is about doing the same thing but for controls placed in headers and footers. After hours trying I came up with the following code. The code works but in all aspects is uglier the the previous one.

var bokMark = ctlMarker.HeaderOrFooter.Range.Bookmarks.Add("A" + Guid.NewGuid().ToString().Replace('-', '_'));

bokMark.Start += contnCtl.Range.Start - bokMark.Start - 1;

bokMark.End += -(bokMark.End - contnCtl.Range.End) + 2;

bokMark.Range.Select();

Object rangeObject = bokMark.Range;

var gcc = bokMark.Range.ContentControls.Add(IWord.WdContentControlType.wdContentControlGroup, ref rangeObject);

我不知道其他办法。所以首先我创建包含整个标题的书签。然后我将其缩小到我现有的控制区域(contnCtl),然后使用书签范围添加GroupContentControl。它太麻烦了,必须有另一种方式。问题
这里:

I coudn't figure out other way. So first I create bookmark embracing entire header. Then I narrow it down to my existing control area (contnCtl) then use bookmarks range to add a GroupContentControl. It is so cumbersome that there must be anther way. Problems here:

a)如果Select是注释代码不起作用(例如:此方法或属性不可用,因为当前选择部分涵盖纯文本内容控件) ;

a) if Select is commented code doesnt work (exeption saying: This method or property is not available because the current selection partially covers a plain text content control);

b)代码完全破坏Word用户界面视图 - 打开标题窗口并进入草稿视图模式(我想Select会导致 - 比,如何摆脱select?)

b) code completely breaks Word user interface view - opens header window and enters draft view mode (I suppose that Select causes that - than, how to get rid of select?)

如何让它很好地运作?

-

愿望













推荐答案

Hi,

根据我的测试,我找不到任何其他方法来实现这一目标。

Base on my test, I don’t find any other way to achieve that.

我正试图让一些高级工程师参与这个问题,这需要一些时间。非常感谢您的耐心。

I'm trying to involve some senior engineers into this issue and it will take some time. Your patience will be greatly appreciated.

最好的问候

Starain


这篇关于如何在页眉或页脚中添加ContentContol?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆