Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 321
Len White Avatar asked Oct 21 '25 20:10

Len White


1 Answers

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.

like image 140
Len White Avatar answered Oct 27 '25 06:10

Len White



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!