问题描述
我有一种情况,需要(以编程方式)将ContextControls
添加到Word
表中.
I have a scenario whereby I need to (programmatically) add ContextControls
to a Word
table.
我的例子是,当用户向表(第一个单元格)添加ContentControl
,然后向该行添加重复的ContentControl
时,这是完美的!
My example is when a user adds a ContentControl
to a table (first cell) then adds a repeating ContentControl
to that row - this is perfect!
如果用户随后转到2单元格表的单元格2(为简单起见)并添加了另一个ContentControl
-请记住,此行已经是重复的ContentControl
,现在只有一个附加的ContentControl
添加后,数据不会重复.
If the user then goes to cell 2 of a 2 cell table (to keep things simple) and adds another ContentControl
- keeping in mind this row is already a repeating ContentControl
and now just has an additional ContentControl
added, the data does not repeat.
如果我进入我的Word
功能区-开发人员,然后打开和关闭滑动设计,则所有数据都会再次正常显示(几乎像重复的ContentControl
一样已被更新/刷新).我想知道-有没有办法通过代码做到这一点?
If I go into my Word
ribbon - Developer, then flick design on and off, the data all appears fine again (almost like the repeating ContentControl
was updated / refreshed). I'm wondering - is there a way to do this through code?
类似重复ContentControl.Update/Refresh/Reload(不存在).
Something like repeating ContentControl.Update / Refresh / Reload (none of those exist).
现在-如果我可以通过Word
应用程序本身做到这一点,我什至会接受,但我会将其转换为代码.
Right now - I'll even accept if I can do this through the Word
application itself, but I will be converting this to code.
推荐答案
对于需要此答案的任何人:
For anyone needing the answer to this:
三天后,我认为完成此任务的最佳方法是两次调用.ToggleFormsDesign
方法.
After 3 days, I've decided that the best way to accomplish this task, is by calling the .ToggleFormsDesign
method twice.
这基本上将刷新/更新"重复的ContentControl上的绑定
This will basically "refresh / update" the binding on the repeating ContentControl
With ActiveDocument
.ToggleFormsDesign
.ToggleFormsDesign
End With
连续调用此方法,不会产生UI/视觉影响(即用户不会注意到任何东西).
Calling this method back to back, will have no UI / visual impact (i.e. the user will not notice anything).
这篇关于更新或刷新Word ContentControls的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!