blog community
APIs for Office Open XML

One of the common comments during the Office Open XML workshops I have been doing is that typing XML markup can be a bit tedious, one thing I fully agree on and one of the reasons why I developed OpenXMLObjects (which is now a bit dead due to the little dev time I have left over lately).

As of yesterday, 10:00 PM, there is a new Microsoft built API out there to shield you a bit from the difficulties of working with XML and packages. The current focus point of this library is a higher-level abstraction of the Open Packaging Convention. The Packaging API which already shipped earlier has some difficulties. One example of this is removing parts in a package. The Packaging API does not tell you which parts are a parent, only information about all children is provided. As long as a part has parents, you should not delete it. This usually means lots of searching for you, but the API now does that for you instead.

The abstractions provided do not yet implement an API for working with the XML markup, only the OPC abstraction is provided yet.

public static void AddImagePart(string path, string imagePath)
{
using (WordprocessingDocument wordDoc = WordprocessingDocument.Open(path, true))
{
MainDocumentPart mainPart = wordDoc.MainDocumentPart;

ImagePart imagePart = mainPart.AddImagePart(ImagePartType.Jpeg);

using (FileStream stream = new FileStream(imagePath, FileMode.Open))
{
imagePart.FeedData(stream);
}
}
}

Perhaps the dev team can take a look at OpenXML4J, built by my friend Julien Chable. Or the PHP framework from Maarten Balliauw J

When you have any questions about this API, visit the forum and let Doug, Julien, me or other Open XML guys help you out!


Posted 05-06-2007 11:15 by Anonymous
Powered by Community Server (Commercial Edition), by Telligent Systems