简体   繁体   中英

Do you have to save the Open XML document after working on it?

Sorry, here's a stupid question. I've been working on a document using the Open XML SDK and I don't see the changes I've made to it after I dispose off the SpreadsheetDocument object.

using (var spreadsheet = SpreadsheetDocument.Open(file, true))
{
    // do stuff to the document
}


// when I exit the program and open the workbook as an end-user
// I don't see any of the changes I made

I think I used to see the changes with examples I did before but I can't be so sure.

Do you have to save the document after working on it to see the changes? I don't see such a method to save the document.

Sorry, a little bit of searching revealed to me what I'd forgotten. Apparently, you have to save the XML DOM you just updated.

Since I updated the WorksheetPart , and the WorksheetPart is of type OpenXmlPart and its DOM is represented by the Worksheet property of type Worksheet , I had to do this:

using (var spreadsheet = SpreadsheetDocument.Open(file, true))
{
    // do stuff to the document

    // finally
    worksheetPart.Worksheet.Save();
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM