Jaa


Open XML SDK – tech preview

Last week I pointed out the open source project to create a Java library for programming against the open xml formats. Well today at TechEd we announced the release of an early preview of a managed API for the Open XML formats. It's available for download here: https://www.microsoft.com/downloads/details.aspx?FamilyId=AD0B72FB-4A1D-4C52-BDB5-7DD7E816D046&displaylang=en

This is another tool that will help make it easier for developers to build solutions on top of the Office file formats. The easier we can make it for people to build solutions, the more valuable the documents themselves become. This is a very early preview and we're hoping to get a lot of great feedback to help shape the evolution of these APIs. There is a discussion forum where you can ask questions, and provide feedback on things you'd like to see added or changed. We'll then take this feedback and use it to help generate future CTPs. You can get to the forum here: https://forums.microsoft.com/MSDN/ShowForum.aspx?ForumID=1647&SiteID=1

The goal in this first CTP was to provide some additional structure on top of what was already provided by System.IO.Packaging in .Net 3.0. Now instead of just generic parts and relationships, you actually have each part from the Open XML spec available as a strongly typed part. The API also provides package level validation so you'll know your creating all the necessary content type declarations and relationship type references.

Here's an example of how you could quickly delete a part in a spreadsheet and then validate the package:

public void ValidateSimplePackage(string xlsxFile)
{
  SpreadsheetDocument xlsxDoc = SpreadsheetDocument.Open(xlsxFile, true);
  Using(xlsxDoc)
  {
    // Remove the main workbook part.
    xlsxDoc.DeletePart(xlsxDoc.WorkbookPart);
    // Validate the package. Will return an exception
    // because of the missing part.
    xlsxDoc.Validate(null);
  }
}

And here's an example of how you could quickly get the comments from a wordprocessing document.

public static string GetCommentsFromDocument(string document)
{
  string comments = null;
  using (WordprocessingDocument wordDoc = WordprocessingDocument.Open(document, true))
  {
    MainDocumentPart mainPart = wordDoc.MainDocumentPart;
    CommentsPart commentsPart = mainPart.CommentsPart;
    using (StreamReader streamReader = new StreamReader(commentsPart.GetStream()))
    {
      comments = streamReader.ReadToEnd();
    }
  }
  return comments;
}

I encourage everyone to take a look and let us know what you think.

-Brian

Comments

  • Anonymous
    June 04, 2007
    Whilst you don't have to use any Microsoft tools or technology to create, manipulate or consume OpenXML

  • Anonymous
    June 04, 2007
    I was reading Brian Jones' post this morning on the Open XML SDK tech preview which is a new managed

  • Anonymous
    June 05, 2007
    Some more folks posted about the Open XML formats SDK which we released yesterday as a technology preview:

  • Anonymous
    June 05, 2007
    I was so busy with activities related to the announcement of the new SDK yesterday that I didn't get

  • Anonymous
    June 05, 2007
    Of course while I'm off creating more Office Open XML nuggets about the System.IO.Packaging APIs, the

  • Anonymous
    June 12, 2007
    MSN I NIIPET <a href="http://msn.com">MSN</a>

  • Anonymous
    June 12, 2007
    What a day at Tech ED! Today Doug Mahugh announced during his session the new Open XML Object Model and

  • Anonymous
    June 13, 2007
    The good thing about having too much work to do when I got back from TechEd is that by now other people

  • Anonymous
    June 13, 2007
    I was just having a look at the Office Developer Center on MSDN and I noticed this blog post from Erika

  • Anonymous
    June 14, 2007
    [... Today I saw posted on the MSDN Blogs a little post referring to the newly release of the Microsoft's SDK for interacting with such formats from .NET ... ] Pingback from http://samiqbits.blogspot.com

  • Anonymous
    June 05, 2008
    Last week I pointed out the open source project to create a Java library for programming against the open xml formats. Well today at TechEd we announced the release of an early preview of a managed API for the Open XML formats. It's available for downloa