andrew coates @coatsy #dpp407 i told you it was a zip file
TRANSCRIPT
![Page 1: Andrew Coates @coatsy #DPP407 I told you it was a ZIP file](https://reader035.vdocuments.us/reader035/viewer/2022062421/56649d6d5503460f94a4de5c/html5/thumbnails/1.jpg)
![Page 2: Andrew Coates @coatsy #DPP407 I told you it was a ZIP file](https://reader035.vdocuments.us/reader035/viewer/2022062421/56649d6d5503460f94a4de5c/html5/thumbnails/2.jpg)
Deep Dive into Documents with the OpenXML SDKAndrew Coates@coatsy
#DPP407
![Page 3: Andrew Coates @coatsy #DPP407 I told you it was a ZIP file](https://reader035.vdocuments.us/reader035/viewer/2022062421/56649d6d5503460f94a4de5c/html5/thumbnails/3.jpg)
#DPP407
Once upon a time …
![Page 4: Andrew Coates @coatsy #DPP407 I told you it was a ZIP file](https://reader035.vdocuments.us/reader035/viewer/2022062421/56649d6d5503460f94a4de5c/html5/thumbnails/4.jpg)
#DPP407
It’s a ZIP fileThere are parts and relationshipsParts are (often) xml
Open Packaging Convention (OPC)
![Page 5: Andrew Coates @coatsy #DPP407 I told you it was a ZIP file](https://reader035.vdocuments.us/reader035/viewer/2022062421/56649d6d5503460f94a4de5c/html5/thumbnails/5.jpg)
#DPP407
I told you it was a ZIP file
![Page 6: Andrew Coates @coatsy #DPP407 I told you it was a ZIP file](https://reader035.vdocuments.us/reader035/viewer/2022062421/56649d6d5503460f94a4de5c/html5/thumbnails/6.jpg)
#DPP407
DocumentsWorkbooksPresentations
Lots of Package Types
![Page 7: Andrew Coates @coatsy #DPP407 I told you it was a ZIP file](https://reader035.vdocuments.us/reader035/viewer/2022062421/56649d6d5503460f94a4de5c/html5/thumbnails/7.jpg)
#DPP407
Documents
Need:document — The root element for a WordprocessingML's main document part, which defines the main document story.body — The container for the collection of block-level structures that comprise the main story.p — A paragraph.r — A run.t — A range of text.
http://msdn.microsoft.com/EN-US/library/office/gg278308(v=office.15).aspx
![Page 8: Andrew Coates @coatsy #DPP407 I told you it was a ZIP file](https://reader035.vdocuments.us/reader035/viewer/2022062421/56649d6d5503460f94a4de5c/html5/thumbnails/8.jpg)
![Page 9: Andrew Coates @coatsy #DPP407 I told you it was a ZIP file](https://reader035.vdocuments.us/reader035/viewer/2022062421/56649d6d5503460f94a4de5c/html5/thumbnails/9.jpg)
#DPP407
Need:A single sheetA sheet IDA relationship Id pointing to the location of the sheet definition
Spreadsheets
http://msdn.microsoft.com/en-us/library/office/gg278316(v=office.15).aspx
![Page 10: Andrew Coates @coatsy #DPP407 I told you it was a ZIP file](https://reader035.vdocuments.us/reader035/viewer/2022062421/56649d6d5503460f94a4de5c/html5/thumbnails/10.jpg)
![Page 11: Andrew Coates @coatsy #DPP407 I told you it was a ZIP file](https://reader035.vdocuments.us/reader035/viewer/2022062421/56649d6d5503460f94a4de5c/html5/thumbnails/11.jpg)
#DPP407
Need:Presentation part, represented by the file presentation.xmlPresentation properties part (presProps.xml)Slide master part (slideMaster.xml)Slide layout part (slideLayout.xml)Theme part (theme.xml)[One or more slide parts (slide.xml)].
Presentations
![Page 12: Andrew Coates @coatsy #DPP407 I told you it was a ZIP file](https://reader035.vdocuments.us/reader035/viewer/2022062421/56649d6d5503460f94a4de5c/html5/thumbnails/12.jpg)
“The packaging structure of a presentation document contains several references between the parts, including some circular references. For example, slide layouts reference slide masters, and slide masters reference slide layouts”http://msdn.microsoft.com/en-us/library/office/gg278335(v=office.15).aspx
![Page 13: Andrew Coates @coatsy #DPP407 I told you it was a ZIP file](https://reader035.vdocuments.us/reader035/viewer/2022062421/56649d6d5503460f94a4de5c/html5/thumbnails/13.jpg)
![Page 14: Andrew Coates @coatsy #DPP407 I told you it was a ZIP file](https://reader035.vdocuments.us/reader035/viewer/2022062421/56649d6d5503460f94a4de5c/html5/thumbnails/14.jpg)
![Page 15: Andrew Coates @coatsy #DPP407 I told you it was a ZIP file](https://reader035.vdocuments.us/reader035/viewer/2022062421/56649d6d5503460f94a4de5c/html5/thumbnails/15.jpg)
#DPP407
Enter the OpenXML SDK
v1.0 2007 OPC Only (xml up to you)
v2.0 2008 Strong Typed, LINQ, Validation
v2.5 2013 Office 2013, read ISO StrictOpen
Sourced
2014
![Page 16: Andrew Coates @coatsy #DPP407 I told you it was a ZIP file](https://reader035.vdocuments.us/reader035/viewer/2022062421/56649d6d5503460f94a4de5c/html5/thumbnails/16.jpg)
OOXMLSDK v1.0static void Main(string[] args){ const string fileName = "Test.docx";
const string documentRelationshipType = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument"; const string stylesRelationshipType = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles";
XDocument xDoc = null; XDocument styleDoc = null;
using (Package wdPackage = Package.Open(fileName, FileMode.Open, FileAccess.Read)) { http://blogs.msdn.com/b/ericwhite/archive/2007/12/20/what-is-the-difference-between-the-system-io-packaging-and-microsoft-office-documentformat-openxml-
packaging-namespaces.aspx
![Page 17: Andrew Coates @coatsy #DPP407 I told you it was a ZIP file](https://reader035.vdocuments.us/reader035/viewer/2022062421/56649d6d5503460f94a4de5c/html5/thumbnails/17.jpg)
OOXMLSDK v1.0 (cont) PackageRelationship docPackageRelationship = wdPackage .GetRelationshipsByType(documentRelationshipType) .FirstOrDefault(); if (docPackageRelationship != null) { Uri documentUri = PackUriHelper .ResolvePartUri( new Uri("/", UriKind.Relative), docPackageRelationship.TargetUri); PackagePart documentPart = wdPackage.GetPart(documentUri);
// Load the document XML in the part into an XDocument instance. xDoc = XDocument.Load(XmlReader.Create(documentPart.GetStream()));
![Page 18: Andrew Coates @coatsy #DPP407 I told you it was a ZIP file](https://reader035.vdocuments.us/reader035/viewer/2022062421/56649d6d5503460f94a4de5c/html5/thumbnails/18.jpg)
OOXMLSDK v1.0 (cont (cont)) // Find the styles part. There will only be one. PackageRelationship styleRelation = documentPart.GetRelationshipsByType(stylesRelationshipType) .FirstOrDefault(); if (styleRelation != null) { Uri styleUri = PackUriHelper.ResolvePartUri(documentUri, styleRelation.TargetUri); PackagePart stylePart = wdPackage.GetPart(styleUri);
// Load the style XML in the part into an XDocument instance. styleDoc = XDocument.Load(XmlReader.Create(stylePart.GetStream())); } } }
![Page 19: Andrew Coates @coatsy #DPP407 I told you it was a ZIP file](https://reader035.vdocuments.us/reader035/viewer/2022062421/56649d6d5503460f94a4de5c/html5/thumbnails/19.jpg)
OOXMLSDK v1.0 (cont (cont (cont))) Console.WriteLine("The main document part has {0} nodes.", xDoc.DescendantNodes().Count()); Console.WriteLine("The style part has {0} nodes.", styleDoc.DescendantNodes().Count()); Console.ReadKey();}
![Page 20: Andrew Coates @coatsy #DPP407 I told you it was a ZIP file](https://reader035.vdocuments.us/reader035/viewer/2022062421/56649d6d5503460f94a4de5c/html5/thumbnails/20.jpg)
OOXMLSDK v2.0static void Main(string[] args){ const string fileName = "Test.docx"; using (WordprocessingDocument doc = WordprocessingDocument.Open(fileName, false)) { MainDocumentPart mainPart = doc.MainDocumentPart; StyleDefinitionsPart stylePart = mainPart.StyleDefinitionsPart; Console.WriteLine("The main document part has {0} descendents.", mainPart.RootElement.Descendants().Count()); Console.WriteLine("The style part has {0} descendents.", stylePart.RootElement.Descendants().Count()); Console.ReadKey(); }}
![Page 21: Andrew Coates @coatsy #DPP407 I told you it was a ZIP file](https://reader035.vdocuments.us/reader035/viewer/2022062421/56649d6d5503460f94a4de5c/html5/thumbnails/21.jpg)
#DPP407
All documents (packages) have the same base structureYou can build a document from scratch (it’s just a zip file and xml)It’s MUCH easier to use the OpenXML SDK
OpenXML
![Page 22: Andrew Coates @coatsy #DPP407 I told you it was a ZIP file](https://reader035.vdocuments.us/reader035/viewer/2022062421/56649d6d5503460f94a4de5c/html5/thumbnails/22.jpg)
#DPP407
Building Simple OOXML Documents
![Page 23: Andrew Coates @coatsy #DPP407 I told you it was a ZIP file](https://reader035.vdocuments.us/reader035/viewer/2022062421/56649d6d5503460f94a4de5c/html5/thumbnails/23.jpg)
#DPP407
Deconstructing
![Page 24: Andrew Coates @coatsy #DPP407 I told you it was a ZIP file](https://reader035.vdocuments.us/reader035/viewer/2022062421/56649d6d5503460f94a4de5c/html5/thumbnails/24.jpg)
#DPP407
Manual deconstruction
![Page 25: Andrew Coates @coatsy #DPP407 I told you it was a ZIP file](https://reader035.vdocuments.us/reader035/viewer/2022062421/56649d6d5503460f94a4de5c/html5/thumbnails/25.jpg)
#DPP407
Programmatic Deconstruction(& reconstruction)
![Page 26: Andrew Coates @coatsy #DPP407 I told you it was a ZIP file](https://reader035.vdocuments.us/reader035/viewer/2022062421/56649d6d5503460f94a4de5c/html5/thumbnails/26.jpg)
#DPP407
Constructing
![Page 27: Andrew Coates @coatsy #DPP407 I told you it was a ZIP file](https://reader035.vdocuments.us/reader035/viewer/2022062421/56649d6d5503460f94a4de5c/html5/thumbnails/27.jpg)
#DPP407
Complex Document
![Page 28: Andrew Coates @coatsy #DPP407 I told you it was a ZIP file](https://reader035.vdocuments.us/reader035/viewer/2022062421/56649d6d5503460f94a4de5c/html5/thumbnails/28.jpg)
#DPP407
Templated Document
![Page 29: Andrew Coates @coatsy #DPP407 I told you it was a ZIP file](https://reader035.vdocuments.us/reader035/viewer/2022062421/56649d6d5503460f94a4de5c/html5/thumbnails/29.jpg)
#DPP407
SpreadsheetsShared String TableCalculation ChainFormulasPivotTables
PresentationsAnimationsHandouts/Notes
DocumentsStylesThemes
What I Haven’t Covered
![Page 30: Andrew Coates @coatsy #DPP407 I told you it was a ZIP file](https://reader035.vdocuments.us/reader035/viewer/2022062421/56649d6d5503460f94a4de5c/html5/thumbnails/30.jpg)
#DPP407
Open XML SDK on GitHub - https://github.com/OfficeDev/Open-Xml-SdkBrian Jones' blog announcing open sourcing the SDK http://blogs.office.com/2014/06/25/open-xml-sdk-goes-open-source/Open XML SDK 2.5 Docs - http://msdn.microsoft.com/en-us/library/office/bb448854(v=office.15).aspxOpen XML Developer Site - http://openxmldeveloper.org/About the Open XML SDK 2.5 for Office - http://msdn.microsoft.com/en-us/library/office/bb456487(v=office.15).aspxWorking with WordprocessingML documents (Open XML SDK) - http://msdn.microsoft.com/en-us/library/office/gg278327(v=office.15).aspxWorking with PresentationML documents (Open XML SDK) - http://msdn.microsoft.com/en-us/library/office/gg278318(v=office.15).aspxWorking with SpreadsheetML documents (Open XML SDK) - http://msdn.microsoft.com/en-us/library/office/gg278328(v=office.15).aspx
Resources
![Page 31: Andrew Coates @coatsy #DPP407 I told you it was a ZIP file](https://reader035.vdocuments.us/reader035/viewer/2022062421/56649d6d5503460f94a4de5c/html5/thumbnails/31.jpg)
#DPP407
ISO/IEC 29500-1:2012 - http://www.iso.org/iso/home/store/catalogue_tc/catalogue_detail.htm?csnumber=61750Open XML SDK .NET Foundation Page - http://www.dotnetfoundation.org/prjopenxml.aspxOpen XML Package Editor Released for VS2012 and VS2013 - http://openxmldeveloper.org/blog/b/openxmldeveloper/archive/2014/06/07/open-xml-package-editor-released-for-vs2012-and-vs2013.aspx
http://visualstudiogallery.msdn.microsoft.com/450a00e3-5a7d-4776-be2c-8aa8cec2a75bhttp://blogs.msdn.com/b/acoat/archive/2010/06/19/document-creation-and-conversion-with-the-openxml-sdk-and-sharepoint-2010-word-automation-services.aspxhttp://blogs.msdn.com/b/acoat/archive/2011/04/06/document-creation-and-conversion-with-the-openxml-sdk-and-sharepoint-2010-word-automation-services-part-2.aspx
Resources (cont)
![Page 32: Andrew Coates @coatsy #DPP407 I told you it was a ZIP file](https://reader035.vdocuments.us/reader035/viewer/2022062421/56649d6d5503460f94a4de5c/html5/thumbnails/32.jpg)
#DPP407
Build Awesome Documents
Fast
![Page 33: Andrew Coates @coatsy #DPP407 I told you it was a ZIP file](https://reader035.vdocuments.us/reader035/viewer/2022062421/56649d6d5503460f94a4de5c/html5/thumbnails/33.jpg)
Deep Dive into Documents with the OpenXML SDKAndrew Coates@coatsy
#DPP407
![Page 34: Andrew Coates @coatsy #DPP407 I told you it was a ZIP file](https://reader035.vdocuments.us/reader035/viewer/2022062421/56649d6d5503460f94a4de5c/html5/thumbnails/34.jpg)
Thanks! Don’t forget to complete your evaluations
aka.ms/mytechedmel