Working with Packaging

Overview

An .xlsx file is an OOXML ZIP package. Workbook::Save() and the Workbook loading constructor handle this package structure automatically for everyday use — most applications never need the classes on this page directly.


The Package Model

PackageModel represents the raw package: its Parts, Relationships, and any UnsupportedParts encountered while reading. PackageLoadContext ties a loaded Workbook to the PackageModel it was read from, exposing both via its Workbook and Package properties.

Reading and Writing Packages

IPackageReader and IPackageWriter are the interfaces the library’s internal ZIP handling implements. PackagingConventions provides the well-known OPC part and relationship names the library relies on internally (for example, the content-types part and the workbook’s root relationship).

Error Handling

PackageStructureException and MissingPartException are raised when a package is missing a required part or otherwise does not conform to the expected structure. RelationshipDescriptor and RelationshipResolutionException relate to resolving OPC relationships between package parts.


Tips and Best Practices

  • Use Workbook’s own Save()/loading constructor for everyday work — the packaging classes on this page are the implementation layer underneath them, not a typical application’s entry point.

Common Issues

IssueCauseFix
PackageStructureException on loadThe ZIP package is missing a required OPC partLoad with LoadOptions->TryRepairPackage = true instead of handling the package model directly

API Reference Summary

Class/MethodDescription
PackageModelIn-memory model of an OPC package (Parts, Relationships, UnsupportedParts)
PackageLoadContextTies a loaded Workbook to its source PackageModel
IPackageReader / IPackageWriterInterfaces for reading/writing the underlying ZIP package
PackagingConventionsWell-known OPC part and relationship name helpers
PackageStructureException / MissingPartExceptionRaised on a malformed or incomplete package

See Also