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 ownSave()/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
| Issue | Cause | Fix |
|---|---|---|
PackageStructureException on load | The ZIP package is missing a required OPC part | Load with LoadOptions->TryRepairPackage = true instead of handling the package model directly |
API Reference Summary
| Class/Method | Description |
|---|---|
PackageModel | In-memory model of an OPC package (Parts, Relationships, UnsupportedParts) |
PackageLoadContext | Ties a loaded Workbook to its source PackageModel |
IPackageReader / IPackageWriter | Interfaces for reading/writing the underlying ZIP package |
PackagingConventions | Well-known OPC part and relationship name helpers |
PackageStructureException / MissingPartException | Raised on a malformed or incomplete package |