Welcome to MSDN Blogs Sign in | Join | Help

Open XML Code Snippets on Channel 9 - UPDATE

I recorded a screencast for Channel9 last week in which I walk you through a few of the code snippets we shipped for working with Office Open XML files using .NET 3.0.  I take you through three snippets:

1. How to find the officeDocument part, or "start part" -  This snippet is particularly useful.  The officeDocument part is related from the package and represents the start of the tree of parts (graph, really) that represents the Office document.  Once you've found this part, you can start working through the relationships and parts to find what you need.  This is the only snippet that works with all three file types (documents, workbooks and presentations).

2.  Document data redaction -  With this snippet I show you how to remove a VBA project part from a Word Document, and convert the document from a Macro-Enabled Word Document to a Macro-Free Word Document.

3.  Finally, I show how to insert a string value into a Workbook.  This is particularly handy as Open XML workbooks store the strings in a shared string table part, seperate from the individual sheets.

There are forty snippets altogether, and I'll spend some more time in this blog discussing them in depth. 

 UPDATE:  We got the screencast posted late today.  Sorry about the inconvience.  Doug was out when we noticed the bad link. His email had an OOF message pointing to another person, who had an OOF message that pointed to another person, who.....  By the time I got through all the cascading OOF's, Doug had arrived at his destination and updated the link.  Thanks Doug!

Published Monday, January 29, 2007 8:24 AM by KevinBoske

Comments

# re: Open XML Code Snippets on Channel 9

I'd be baffled if the screencast displays, when you know the movie source is : \\word\public\Jobailor\kboskecodesnippetsone\kboskecodesnippetsone.swf

Monday, January 29, 2007 2:22 PM by Stephane Rodriguez

# re: Open XML Code Snippets on Channel 9

Yikes!  Thanks Stephane, I've emailed Doug and asked him to fix the link.  I didn't watch myself again after it was posted, (I can't stand to hear my own voice played back to me).

Monday, January 29, 2007 2:43 PM by KevinBoske

# re: Open XML Code Snippets on Channel 9

The post is updated with the actual screencast now, sorry about that everyone.

Tuesday, January 30, 2007 8:54 PM by KevinBoske

# re: Open XML Code Snippets

Kevin -

 I have been following your blog and playing with the code snippets to modify some office addins at my company.  I am having some issues with the WDSetCustomProperty snippet for Word.  If the custom.xml file exists, then all seems fine to add properties and modify them, but if the document part does not exist, and needs to be added by the snippet, then it corrupts the file.  I have been trying to figure out where the error may be but am running into a dead end.  I was just wondering if you or others were having success or troubles with this snippet?

If this comment is in the wrong place I apologize.

Thanks

Brian

Wednesday, February 21, 2007 2:45 PM by Brian

# re: Open XML Code Snippets

It appears that I need to programmatically add an override to the [content_types].xml file in the package, since that is not taken care of when the new document part is added.  I am getting closer, but still need to perform the above task, which I am not finding a method for in the System.IO.Packaging namespace?

Wednesday, February 21, 2007 5:03 PM by Brian

# re: Open XML Code Snippets

Well, this will be my last post on your blog for a while.  I just wanted to update this on the bug that I potentially found in the snippet that I was mentioning.  When it calls the following code to add the custom.xml part if it does not exist, one of the parameters is not right.

customPropsPart = wdPackage.CreatePart(customPropsUri, "application/xml")

Rather it should be something like,

'customPropsPart = wdPackage.CreatePart(customPropsUri, "application/vnd.openxmlformats-officedocument.custom-properties+xml")

Again, sorry for the successive posts.

Thanks

Brian

Wednesday, February 21, 2007 5:47 PM by Brian

# re: Open XML Code Snippets on Channel 9 - UPDATE

Hey Brian,

Thanks for reading, and thanks for the bug. Good catch.  You've got it right, you need to set the "custom-properties+xml" content type.

Sorry I am so late returning your comment, I was out on vacation when you posted, but I'm back now.  Expect to see some more posts soon.

Wednesday, March 07, 2007 1:02 PM by KevinBoske

# re: Open XML Code Snippets on Channel 9 - UPDATE

Du musst ein Fachmann sein - wirklich guter Aufstellungsort, den du hast!

Wednesday, March 14, 2007 9:04 PM by ...

# re: Open XML Code Snippets on Channel 9 - UPDATE

Hi, I've been using OpenXML with VB.NET to create word documents.

I'm having real trouble trying to add tables/rows/columns programatically.  I can't find any vb.net samples that add rows or columns anywhere.  If you are aware of any could you send to dfrench@biztechsoftware.co.uk

Wednesday, April 11, 2007 12:04 PM by Dermot French
New Comments to this post are disabled
 
Page view tracker