Recently, we developed the Open xml sdk 2.0 and VSTO on Word. When a Word file is generated, XML ing is used to bind the XML in the Content Control (ContentControl) and custom xml part (CustomXMLPart). When editing the document, VSTO is used for dynamic Word operations.
When editing a Word document, the content control (ContentControl) is dynamically added, and the xml is modified for xml ing. This will happenOne problemYes:The undo and redo operations of a Word document only affect the content control, but not the XML in the Custom xml part (CustomXMLPart )., ThinkSolutionIs to disable the Word document undo and redo operations. After google on the Internet, the undo and redo functions cannot be disabled in Word documents, and the maximum number of undo and redo stacks cannot be modified. However, the undo and redo stacks can be cleared.
Clear the undo stack of the current document
Sub ClearActiveDocumentUndoStack ()
ActiveDocument. UndoClear
End Sub
Clear all undo stacks that open the document
Sub ClearAllDocumentsUndoStack ()
Dim oDocUndoStack as Object
For Each oDocUndoStack In Application. Documents
ODocUndoStack. UndoClear
Next oDocUndoStack
End Sub
The Document in C # also has the corresponding UndoClear method. The undo stack is indeed cleared, and redo should be impossible, as described in the article, however, it can still be used in Word2010. I had to use a trick (trick). After UndoClear is called, just select something. Redo operations are only select operations with no adverse consequences.
Reference: WD2000: How to Clear the Undo Stack