Presentation is loading. Please wait.

Presentation is loading. Please wait.

OPEN XML SDK FOR MICROSOFT OFFICE John DeVight September 21, 2013 TechGate 2013 – Reston, VA.

Similar presentations


Presentation on theme: "OPEN XML SDK FOR MICROSOFT OFFICE John DeVight September 21, 2013 TechGate 2013 – Reston, VA."— Presentation transcript:

1 OPEN XML SDK FOR MICROSOFT OFFICE John DeVight September 21, 2013 TechGate 2013 – Reston, VA

2 INTRODUCTIONS John DeVight Herndon, Virginia Senior Principal Software Engineer at ManTech Telerik MVP

3 AGENDA About the Open XML SDK Library (2 minutes) “Telerik Products” Demo (3 minutes) Getting Started (5 minutes) Installing the Open XML SDK Library Reference the Open XML SDK Library Open XML SDK 2.0 Productivity Tool Creating Word Documents (30 minutes) Using “Open XML SDK 2.0 Productivity Tool for MS Office” Using Bookmarks Using XSLT Creating Excel Documents (10 minutes) Using “Open XML SDK 2.0 Productivity Tool for MS Office” Using the SDK Directly Using SpreadsheetLight

4 ABOUT THE OPEN XML SDK LIBRARY: WHAT IS IT? “ The Open XML SDK 2.0 simplifies the task of manipulating Open XML packages and the underlying Open XML schema elements within a package. The Open XML SDK 2.0 encapsulates many common tasks that developers perform on Open XML packages, so that you can perform complex operations with just a few lines of code.” 1 An Open XML Package is a zip file containing XML documents, images and other files needed to display the document in a Microsoft Office application min

5 “TELERIK PRODUCTS” DEMO

6 GETTING STARTED: INSTALLING THE OPEN XML SDK LIBRARY Open XML SDK 2.0 for Microsoft Office Download Install the “Open XML SDK” from the OpenXMLSDKv2.msi installer. Install the “Open XML SDK Productivity Tool for Microsoft Office” from the OpenXMLSDKTool.msi installer. 5 min45 min

7 GETTING STARTED: REFERENCE THE OPEN XML SDK LIBRARY In the.NET application, reference: * WordLite is a class library that I created to make it easier to work with Word Documents. ** SpreadsheetLight is freely available under the MIT License that simplifies using the Open XML SDK Library when creating Excel Documents. SpreadsheetLight AssemblyVisual Studio 2012 DocumentFormat.OpenXmlAssemblies -> Extensions WindowsBaseAssemblies -> Framework *WordLiteBrowse ** SpreadsheetLightBrowse

8 GETTING STARTED: OPEN XML SDK 2.0 PRODUCTIVITY TOOL Open Microsoft Office document and generate C# code to create the same document. View the Open XML SDK Documentation.

9 CREATING WORD DOCUMENTS: OPTIONS Open XML SDK 2.0 Productivity Tool for MS Office Bookmarks XSLT 10 min40 min

10 CREATING WORD DOCUMENTS: USING “OPEN XML SDK 2.0 PRODUCTIVITY TOOL” Pros All the code is generated for you. Fast and Easy. Cons The tool generates a lot of code. Every change requires the code to be updated and deployed.

11 CREATING WORD DOCUMENTS: USING “OPEN XML SDK 2.0 PRODUCTIVITY TOOL” Create and Save Word Document Open the Word Document using “Open XML SDK 2.0 Productivity Tool” In “Document Explorer”, right-click on root and select “Reflect Code”. Create console app in Visual Studio. Add references to required assemblies. Create new class for the “generated code”. Instantiate class and call CreatePackage from Main.

12 CREATE WORD DOCUMENTS: USING BOOKMARKS Pros Easy to create and update the “template” document without having to write code. The end user could create their own “template” documents. Cons Requires code to know about all the bookmarks. 15 min35 min

13 CREATE WORD DOCUMENTS: USING BOOKMARKS: “REAL WORLD” IMPLEMENTATION Application for police departments to create Wanted Posters.

14 CREATE WORD DOCUMENTS: USING BOOKMARKS – CREATE “TEMPLATE” DOCUMENT Create Word Document Insert Bookmark Insert -> Bookmark Give the bookmark a name Click “Add” button Making Bookmarks visible File -> Options Advanced -> Show document content Show bookmarks

15 CREATE WORD DOCUMENTS: USING BOOKMARKS Demo Bookmarks in a Word Document

16 CREATE WORD DOCUMENTS: USING BOOKMARKS Header and Footer Bookmarks Create Header Insert -> Header Insert Bookmark Insert -> Bookmark Give the bookmark a name Click “Add” button Design -> Close Header and Footer 20 min30 min

17 CREATE WORD DOCUMENTS: USING BOOKMARKS AND WORDLITE Open a word document with Bookmarks. Replace bookmarks with text. Replace image. Get the header and replace bookmark with text. Get the footer and replace bookmark with text.

18 CREATE WORD DOCUMENTS: USING BOOKMARKS Identifying the header and footer Open the document in the “Open XML SDK 2.0 Productivity Tool”. Open each header and footer and look for the bookmark. Identifying the image name (option 1) Open the document in the “Open XML SDK 2.0 Productivity Tool” Locate the image. Identifying the image name (option 2) Change the extension on the Word document to.zip Extract the contents of the.zip file and look at each image.

19 CREATE WORD DOCUMENTS: USING BOOKMARKS AND WORDLITE Review WordController.ProductBookmarks Controller Action.

20 CREATE WORD DOCUMENTS: USING BOOKMARKS AND WORDLITE Add bookmark to the document. Replace bookmark with image. “kendo.png”, "image/png"); 25 min

21 CREATE WORD DOCUMENTS: USING BOOKMARKS Demo Allowing End User to Create Templates

22 CREATING WORD DOCUMENTS: USING XSLT Pros Templates can be changed without having to recompile..NET code is simplified. Good approach when the document format does not change much over time. Cons Templates can get a bit complicated to manipulate. 30 min20 min

23 CREATING WORD DOCUMENTS: USING XSLT : “REAL WORLD” IMPLEMENTATION Creating Government Contracting Documents

24 CREATING WORD DOCUMENTS: REVIEW OPEN XML PACKAGE DEFINITION An Open XML Package is a zip file containing XML documents, images and other files needed to display the document in a Microsoft Office application.

25 CREATING WORD DOCUMENTS: USING XSLT Create Word Document Put “placeholders” for values Save document Create XSLT file Rename.docx to.zip Open zip file and get the word/document.xml file Rename with.xslt extension Replace: With: Add to the end of the file:

26 CREATING WORD DOCUMENTS: USING XSLT products.xml XPath editor -

27 CREATING WORD DOCUMENTS: USING XSLT

28 CREATING WORD DOCUMENTS: USING XSLT Demo Implementing XSL Template. Review WordController.ProductXslt Controller Action.

29 CREATING WORD DOCUMENTS: USING XSLT Adding C# Support to XSLT xmlns:msxsl="urn:schemas-microsoft-com:xslt“ xmlns:cs="urn:custom-csharp“ 35 min15 min

30 CREATING WORD DOCUMENTS: USING XSLT Demo Implementing C# Support to XSLT Review WordController.ProductXsltWithScript Controller Action.

31 CREATING WORD DOCUMENTS: USING XSLT Adding Header and Footer Create document with header and footer Rename.docx to.zip Open zip file and get the word/header.xml file and word/footer.xml file Rename with.xslt extension Replace: With: Add to the end of the file:

32 CREATING WORD DOCUMENTS: USING XSLT Review WordController.ProductXsltWithHeaderFooter Controller Action.

33 CREATING EXCEL DOCUMENTS: OPTIONS Open XML SDK 2.0 Productivity Tool for MS Office Using the SDK Using SpreadsheetLight 40 min10 min

34 CREATING EXCEL DOCUMENTS: “OPEN XML SDK 2.0 PRODUCTIVITY TOOL” Create and Save Excel Document Open the Excel Document using “Open XML SDK 2.0 Productivity Tool” In “Document Explorer”, right-click on root and select “Reflect Code”. Create console app in Visual Studio. Add references to required assemblies. Create new class for the “generated code”. Instantiate class and call CreatePackage from Main.

35 CREATING EXCEL DOCUMENTS: USING THE SDK Code Project article: Creating basic Excel workbook with Open XML by Mika WendeliusCreating basic Excel workbook with Open XMLMika Wendelius

36 CREATING EXCEL DOCUMENTS: USING SPREADSHEETLIGHT “SpreadsheetLight is an open source spreadsheet library/component for.NET Framework written in C#. It is freely available and uses the MIT License. It generates Open XML spreadsheets that are compatible with Microsoft Excel 2007/2010/2013 (and even LibreOffice Calc).”

37 CREATING EXCEL DOCUMENTS: USING SPREADSHEETLIGHT Features used: Setting Document Properties Rename Worksheet Set Column Heading Styles Set Column Widths Format Currency Cells Define Formulas Create Charts Protect Worksheet

38 CREATING EXCEL DOCUMENTS: USING SPREADSHEETLIGHT Demo using SpreadsheetLight Review ExcelController.SalesByYear Controller Action.

39 CREATING EXCEL DOCUMENTS: USING SPREADSHEETLIGHT Adding a Chart SLChart CreateChart – define the range for the data to be used. SetChartType – set the type of chart to create SetChartPosition – where the chart will appear in the worksheet SetChartStyle – style for the chart. SLDocument.InsertChart – insert the chart into the current worksheet. 45 min5 min

40 CREATING EXCEL DOCUMENTS: USING SPREADSHEETLIGHT Demo creating Chart Review ExcelController.SalesByYearWithChart Controller Action.

41 PRESENTATION AND SOURCE CODE Where can I find the presentation and source code?

42 QUESTIONS

43 FUTURE PRESENTATIONS Creating MVC Extensions for the jQuery UI Library that can be used with the Razor and ASPX (WebForms) View Engines.jQuery UI Library Creating mobile application games using the “Crafty” JavaScript Gaming Engine and PhoneGap.“Crafty” JavaScript Gaming Engine Creating Desktop/Mobile/Web Applications with HTML5 / JavaScript, node.js, Kendo UI, and node-webkit using the same code base.node.js Kendo UInode-webkit 50 min

44 An will be sent to all attendees on Monday, September 23 announcing location of slides received from presenters.


Download ppt "OPEN XML SDK FOR MICROSOFT OFFICE John DeVight September 21, 2013 TechGate 2013 – Reston, VA."

Similar presentations


Ads by Google