Home > Technology > Create OpenXML Packaging API for .NET 1.1 & .NET 2.0 – Part 1

Create OpenXML Packaging API for .NET 1.1 & .NET 2.0 – Part 1

The adoption of XML (Zipped) as the native file format for Word/Excel/PowerPoint 2007 has opened up a new set of opportunities for software developers to integrate & generate Office files across the platform.  There is absolutely no need to use OLE Automation etc in VB or .NET.

Microsoft System.IO.Packaging comes with .NET 3.0.

About Open XML

Open XML is a file format for representing Microsoft Office documents like word spreadsheets and presentations documents. An OpenXML document file contains mainly XML based files compressed within a zip package.

You can read more about OpenXML formats here: http://msdn.microsoft.com/en-us/library/aa338205.aspx

It is important to have knowledge of Open XML file formats, its structure, about Parts & Relationships and content types to understand this series of article.

Sometimes there are requirement to generate the office files in the software application which is based on .Net 1.1 & .Net 2.0. It cannot be upgraded to .Net 3.0/3.5 because of some internal reasons so it is necessary to build the Packing API which can work with .Net 1.1 & .Net 2.0 so that .docx, .xlsx & .pptx can be created from their system.

This article will be in parts, in part one we will define the interfaces required to build the Packing Library.

An Office file (excel, work, ppt) is a zipped file that contains the folders, xml, images etc. which is called as package and a package can have multiple element which are called PackagePart like Image, comment, notes, header, footer, chart, slide, worksheet & many more.

There is hierarchy of parts and they are related to each other. This relationship is maintained in .rels file inside _rels folder.

Content Type information like xml, text, image, mp3, wav is also stored inside the ZIP Office Package in the Content_Types.xml file.

So based on the structure of Office File Format we can define the following abstract / inherited classes

/// <summary>

/// Abstract Package Class – It represents an office 2007 document (Excel / Word / PPT)

/// </summary>

public abstract class Package

{

}

/// <summary>

/// Abstract PackagePart Class – Holds in the information for a Package Part like Header, Footer, Hyperlink, Image, Chart etc.

/// </summary>

public abstract class PackagePart

{

}

/// <summary>

/// PackageProperties Class – To store the Package core & other Properties like

/// </summary>

public class PackageProperties

{

}

/// <summary>

/// PackageRelationship Class – Stores all relationships

/// </summary>

public partial class PackageRelationship

{

}

/// <summary>

/// ZipPackage Class: Implementation of Package Class.

/// </summary>

public class ZipPackage : Package

{

}

/// <summary>

/// ZipPackagePart Class – Implementation Class for PackagePart

/// </summary>

public class ZipPackagePart : PackagePart

{

}

Package & PackagePart can have multiple implementations based on which ZIP Library you use to zip/unzip your package file.

  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.