Search code examples
openxmlopenxml-sdk

Close OpenXML Document Without Saving


From what I understand, when you open, edit, then close an OpenXML document such as an .DOCX file, the revised document is automatically saved. If you change your mind and decide not to save the edits, is there a way to close the document without saving? I can't seem to find anything.


Solution

  • The document has an AutoSave property, which is set to True by default. The Open method can take an OpenSettings object, which can be used to override the default behavior:

            Imports DocumentFormat.OpenXml.Wordprocessing
    
            Dim os As OpenSettings = New OpenSettings()
            os.AutoSave = False
            Dim doc as Doc = WordprocessingDocument.Open(Path, True, os)
    

    In this case, the document will not be saved unless doc.Save is called. doc.Dispose will simply release the resources without the save.