Welcome to MSDN Blogs Sign in | Join | Help

Open XML Code Snippets Live!

Yesterday our folks at Office Online released the first set of the Open XML Code Snippets to the web. These snippets work with Visual Studio.NET 2005 and are written in C# and VB.NET using the WinFX (oops) .NET 3.0 System.IO.Packaging API.

When we started working on these, I had a list of over 150 scenarios to choose from, but I had to narrow it down, so I focused on scenarios that would help you learn some of the patterns for working with the Open XML Formats but would aslo be resuable in your solutions.  For example, we have snippets for removing parts (Sheets, Slides, Comments, VBA projects).  Removing parts is definately a common scenario.

There's snippets for editing data, like accepting comments by a particular user.  This one is useful as you must not only know the parts to find (Comments) but also must work with the XML in the document. 

There are snippets specicially for each application's files.  We've got snippets for editing data in a cell.  We've got a snippet for reording slides in a presentation.  We've got a snippet for adding RibbonX customizations.  There are over 40 in all.

All the snippets were written in both VB.NET and C# by Ken Getz.  Ken did a great job.  Everytime we made a change to the file format, Ken would update the snippets.  (Of course, we kept improving the file format faster than I could keep up with shipping the snippets).

So, here they are, in Beta 2 format.  Please download them and give them a try.  I think Doug has some more notes over on OpenXMLDeveloper about these. 

I'm out on vacation, posting this from my parents old machine (part of my vacation is to setup their new machine), but I will check the blog periodically. Please report any issues, comments or praise you have for the snippets in the comments of this post.

Published Saturday, June 17, 2006 10:00 AM by KevinBoske

Comments

# Open XML Code Snippets for .NET

If you're using the .NET packaging API to develop code that reads and writes Open XML documents, this...
Saturday, June 17, 2006 3:51 PM by OpenXML Developer

# .NET Code Snippets for Open XML Developers

A comprehensive set of code snippets for the .NET 3.0 packaging API has been released! Get all the details...
Saturday, June 17, 2006 3:57 PM by OpenXML Developer

# Code Snippets for Open XML Development

The Open XML code snippets are out! These are a well-organized set of snippets that do the basic things...
Saturday, June 17, 2006 4:12 PM by Doug Mahugh

# re: Open XML Code Snippets Live!


Great stuff, that really shows when to use it, and when one should perhaps stick to automation. I am not entirely sure with the Excel sheet deletion sample, since references in other worksheets (formulas, etc.) are not deleted, this should essentially result in a corrupt document.

Kudos again.
Saturday, June 17, 2006 4:38 PM by Mike

# Code snippets for working with the Open XML formats

This is my first time on an airplane with wifi, so I'm pleased to bring this news to you from somewhere...
Saturday, June 17, 2006 9:17 PM by Brian Jones: Open XML Formats

# re: Open XML Code Snippets Live!

That's a good point, Mike, you might end up with a corrupted workbook (I think we'd repair on that case). To fix that you can just remove those references. Maybe that's a good idea for another snippet. :)
Sunday, June 18, 2006 11:23 AM by KevinBoske

# re: Open XML Code Snippets Live!


Yep, since there can be such references in a number of objects including conditional formattings, formulas, named ranges, chart data sources, VBA macros, and so on, I believe it's next to impossible to make a worksheet deletion with such a trivial code. I would suggest to use automation instead.

What is perhaps interesting here anyway is the programmability of the xml model versus a typical object model. In a typical object model, you would get the collection of conditional formattings, and then go through it and make changes. Then, get the formulas collection, and go through it. And so on for all impacted objects. But with Xml, if the schema has been defined towards a more declarative goal (disclaimer : I have not checked if that's the case here), you can build a xpath expression that will fix up all references at once without having to go through all the object collections "by hand". It's very important, it means there is a lot less knowledge you are required to have about the Excel document internals.

Sunday, June 18, 2006 4:06 PM by Mike

# Open XML File Formats: What is it, and how can I get started?

Some people have been following the news and are even ahead of most of us already buidling solutions to generate documents using the Open XML File Formats. Some other people are not familiar with this technology and want to learn more about this, so here
Friday, June 23, 2006 4:54 PM by Erika Ehrli

# OpenXML code snippets

I just spotted a great post on the TechEd Bloggers feed from Erika Ehrli - "Open XML File Formats: What...
Tuesday, June 27, 2006 7:41 AM by Notes2Self.net

# Open XML File Format Snippets RTW!

We've released the final version of the code snippets I told you about back in June . These are the same

Tuesday, November 28, 2006 5:25 PM by Kevin Boske - Office Development
New Comments to this post are disabled
 
Page view tracker