在编辑文档内容和自定义xml内容时,Word无法创建单个逻辑可撤消操作 [英] Word fails to create a single logical undo-able operation when editing document content and custom xml content

查看:89
本文介绍了在编辑文档内容和自定义xml内容时,Word无法创建单个逻辑可撤消操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个文档生成系统,我们使用内容控件作为数据的占位符。为了指示内容控件中允许的数据类型,我们维护嵌入在Word文档中的自定义xml文件,可通过ThisDocument.CustomXmlParts访问。
当使用我们的底层Word API将内容控件添加到文档时,我们还在自定义xml部分中添加了一个节点。

We have a document generation system in place where we use Content Controls as placeholders for data. To indicate the type of data allowed within a content control we maintain a custom xml file embedded in the Word document, reachable through ThisDocument.CustomXmlParts. When a content control is added to the document using our and the underlying Word APIs we also adda a node in the custom xml part.

我们注意到的是Word失败即使我们使用ThisDocument.Application.UndoRecord.StartCustomRecord,也可以添加内容控件和添加自定义xml节点的单个逻辑操作。因此,用户可以撤消
创建包含我们元数据的自定义xml节点,同时保留文档中的内容控件。

What we are noticing is that Word fails to make the addition of the content control and the addition of a custom xml node a single logical operation even when we use ThisDocument.Application.UndoRecord.StartCustomRecord. Therefore, the user is able to undo the creation of the custom xml node containing our metadata, while retaining the content control in the document.

例如,以下代码应该创建一个可撤消的记录,但运行此示例会为您提供两个可撤消的记录。

Eg., the following code should create a single undo-able record, but running this sample gives you two undoable records.

private void button1_Click(object sender, RibbonControlEventArgs e)
{
    // the custom xml part is added on document load as a sample
    Office.CustomXMLPart MyCustomXmlPart = Globals.ThisDocument.MyCustomXmlPart;
    // start the logical operation
    Globals.ThisDocument.Application.UndoRecord.StartCustomRecord("Do it");
    // first action is adding a content control using VSTO API's
    var control = Globals.ThisDocument.Controls.AddContentControl(
        "My Control Name", Word.WdContentControlType.wdContentControlRichText);
    // configure it a bit
    control.LockContents = true;
    control.Title = "MyNode";
    control.Tag = "Tag";
    control.SetPlaceholderText(null, null, "MyNode");
    // Create the custom metadata for the control in the embedded XML file. Use the control ID 
    // as a pointer back into the document
    Globals.ThisDocument.MyCustomXmlPart.DocumentElement.AppendChildNode("MyNode", "",
        Microsoft.Office.Core.MsoCustomXMLNodeType.msoCustomXMLNodeElement, control.ID);
    // done with the logical operation
    Globals.ThisDocument.Application.UndoRecord.EndCustomRecord();
}

在Word中运行时,我们得到两个可撤销操作而不是一个。

When running this in Word, we get two undo-able operations not one.

有关错误或是否是Word中的错误的任何帮助?

Any help on what's wrong or on whether this is a bug in Word?

谢谢!

Wouter

推荐答案

有趣的是,如果您交换创建自定义xml节点并创建文档内容(首先执行自定义XML节点,然后执行内容控制),您只能获得1个逻辑操作。

And interestingly enough, if you swap creating the custom xml node and creating the document content around (first do the custom XML node, then do the content control) you do get only 1 logical operation.

直到你也开始更新属性等。

Until you also start updating attributes and such.

此外,当您使用启动事件创建自定义xml部件,添加节点,然后调用UndoClear()时,撤消列表不会被清除!

Also, when you use the startup event to create a custom xml part, add a node, and then call UndoClear(), the undo list is not cleared!

Word中的自定义撤消记录是否有任何工作功能?

Is there any working functionality surrounding custom undo records in Word?


这篇关于在编辑文档内容和自定义xml内容时,Word无法创建单个逻辑可撤消操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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