Improvements Made to the Final Open XML SDK 2.0 compared to the December 2009 CTP
In a previous post, where I announced the release of the Open XML SDK 2.0, I promised to give you guys a list of improvements and breaking changes made to the SDK compared to the December 2009 CTP.
We made a few tweaks to the SDK based on some of the great feedback we received from you guys. The following sections below outline these changes.
Autosave for Creating Documents
One of the changes we made to the SDK is around supporting autosave for document creation. Back in August 2009 we released a CTP that included autosave functionality when modifying parts within the Open XML package. This functionality allowed for changes to be automatically saved into the package, without the need to call Save() methods. We also provided a mechanism to turn off this functionality. This functionality worked great when opening existing files. However, we never added such functionality for newly created documents. That's what we added this time around for the final version of the SDK. Here are the new Create() methods:
- public static WordprocessingDocument Create(Package package, WordprocessingDocumentType type, bool autoSave);
- public static WordprocessingDocument Create(Stream stream, WordprocessingDocumentType type, bool autoSave);
- public static WordprocessingDocument Create(string path, WordprocessingDocumentType type, bool autoSave);
- public static SpreadsheetDocument Create(Package package, SpreadsheetDocumentType type, bool autoSave);
- public static SpreadsheetDocument Create(Stream stream, SpreadsheetDocumentType type, bool autoSave);
- public static SpreadsheetDocument Create(string path, SpreadsheetDocumentType type, bool autoSave);
- public static PresentationDocument Create(Package package, PresentationDocumentType type, bool autoSave);
- public static PresentationDocument Create(Stream stream, PresentationDocumentType type, bool autoSave);
- public static PresentationDocument Create(string path, PresentationDocumentType type, bool autoSave);
Improved Namespace Processing
The older CTPs used a predefined mapping between the XML prefixes and the different namespaces. In other words, the SDK assumed a specific prefix for a specific namespace. For example, a WordprocessingML Paragraph would always write out the element <p> with the prefix w, such as <w:p>. The issue, that some of you brought up, is that the SDK didn't handle custom prefixes defined in XML fragments if those prefixes conflicted with the predefined list of prefixes of the SDK. With the final version of the SDK we fixed this issue. The final version of the SDK should be a lot more robust.
Breaking Changes in the Final Release of the Open XML SDK 2.0
The following table outlines changes made to Open XML SDK classes and attributes where there is a difference in the December 2009 CTP vs. the final RTW version of the Open XML SDK:
December 2009 CTP Class/Attribute Name |
Final RTW SDK Class/Attribute Name |
DocumentFormat.OpenXml.Spreadsheet.ObjectAnchor::Z_order |
DocumentFormat.OpenXml.Spreadsheet.ObjectAnchor::ZOrder |
DocumentFormat.OpenXml.AdditionalCharacteristics |
DocumentFormat.OpenXml.AdditionalCharacteristicsInfo |
DocumentFormat.OpenXml.Wordprocessing.Alias |
DocumentFormat.OpenXml.Wordprocessing.SdtAlias |
DocumentFormat.OpenXml.Wordprocessing.LatentStyleException |
DocumentFormat.OpenXml.Wordprocessing.LatentStyleExceptionInfo |
DocumentFormat.OpenXml.Drawing.Diagrams.Else |
DocumentFormat.OpenXml.Drawing.Diagrams.DiagramChooseElse |
DocumentFormat.OpenXml.Drawing.Diagrams.If |
DocumentFormat.OpenXml.Drawing.Diagrams.DiagramChooseIf |
DocumentFormat.OpenXml.Math.Function |
DocumentFormat.OpenXml.Math.MathFunction |
DocumentFormat.OpenXml.Vml.Handle |
DocumentFormat.OpenXml.Vml.ShapeHandle |
DocumentFormat.OpenXml.Vml.Handles |
DocumentFormat.OpenXml.Vml.ShapeHandles |
DocumentFormat.OpenXml.Office2010.Ink.Property |
DocumentFormat.OpenXml.Office2010.Ink.ContextNodeProperty |
DocumentFormat.OpenXml.CustomProperties.Property |
DocumentFormat.OpenXml.CustomProperties.CustumDocumentProperty |
DocumentFormat.OpenXml.Spreadsheet.Set |
DocumentFormat.OpenXml.Spreadsheet.TupleSet |
DocumentFormat.OpenXml.VariantTypes.VTOStream |
DocumentFormat.OpenXml.VariantTypes.VTOStreamData |
DocumentFormat.OpenXml.VariantTypes.VTStream |
DocumentFormat.OpenXml.VariantTypes.VTStreamData |
DocumentFormat.OpenXml.VariantTypes.VTVStream |
DocumentFormat.OpenXml.VariantTypes.VTVStreamData |
DocumentFormat.OpenXml.CustomProperties.CustumDocumentProperty |
DocumentFormat.OpenXml.CustomProperties.CustomDocumentProperty |
Note: The change from Alias to SdtAlias will affect the most people.
Zeyad Rajabi
Comments
- Anonymous
May 12, 2010
Can you show us how to copy/export a worksheet from one workbook to another? Thank you,
- Abel
Anonymous
May 13, 2010
The comment has been removedAnonymous
May 25, 2010
Hi brian, I am having trouble with the validation code posted in this post: blogs.msdn.com/.../finding-open-xml-errors-with-open-xml-sdk-validation.aspx i would post in comments but they are disabled for that post. there is a forum post that outlines the problem similar to mine: social.msdn.microsoft.com/.../a516bed7-05d7-4d58-8348-0a3a0c5af966Anonymous
May 25, 2010
@mike from my understanding the Open XML sdk is designed for manipulating the underlying XML of the Open XML documents, not for analyzing or data processing. There exists a oledb driver for connecting to excel documents that would allow you to pull out information using SQL syntax. its named "Microsoft.ACE.OLEDB.12.0" for xlsx, xlsm, xlsb files. We use this in our software product and we have tested it on excel files with 100,000 rows.Anonymous
May 26, 2010
The comment has been removedAnonymous
May 27, 2010
Thanks for the suggestions guys. I will plan on writing some future posts on these topics. @adamm_wr - The issue may be due to the encoding of the XML parts. Make sure the encoding is UTF based rather than ANSI.