Open Office’s Open XML SDK Saving Issue

In one of the projects that involved using the Open XML SDK for manipulating the spreadsheet files, I stumbles across some strange issue, i.e. some of the modified worksheet cell items is not get saved into the document.

I’ve spend considerable amount time to investigate this, which involved obtaining the existing source of SDK, resolves compilation issue and examine the save routine.

By examining the workings of save method inside the SDK, I figured out, that although I’ve called PutXDocument and examine the XML result inside the sheets*.xml the data is already saved, but actually there’s another layer inside the Worksheet object that still contains old worksheet data.

So, when the Close method of SpreadsheetDocument is called, it is the layer of original worksheet data that get saved into the OpenXmlPart stream, not the stream that I already modified.

Try to call Worksheet.Save method proves to be useless, because the Close method is actually use the same method when try to save all Open Xml Parts.

So, how to trigger the data flow from the modified Xml data layer back to Worksheet object ? You can use Worksheet.Reload method. This call will cause your modified Xml part flows back into the Worksheet object.

So, at this time, when you try to call the Close method of the SpreadsheetDocument, your XML layer already get saved into the Worksheet object and your modified data inside the Worksheet object will take effect.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: