This project provides a number of extensions to the Open XML SDK 2.6 developed by Microsoft and maintained by Eric White (see https://github.com/OfficeDev/Open-XML-SDK). The Open XML SDK also includes extensions by myself, e.g., saving and cloning, Flat OPC conversion, and document creation from templates.
Functional transformations are an interesting way to implement XML-based features.
The OpenXmlTransformation<TDocument>
class and its subclasses contained in the
ContractArchitect.OpenXml.Transformation
namespace provide a framework for
implementing such transformations:
-
OpenXmlTransformation<TDocument>
: Abstract base class currently defining methods for transforming Flat OPCstring
s, Flat OPCXDocument
s, andWordprocessingDocument
s (SpreadsheetDocument
s andPresentationDocument
s to follow). -
FlatOpcStringTransformation<TDocument>
: Abstract base class that is subclassed by concrete transformations implementing astring
-based transformation. This class automatically translate other supported inputs, i.e.,XDocument
andWordprocessingDocument
(at this time) into astring
and thestring
transformed byTransform(string)
back into the original format. -
FlatOpcDocumentTransformation<TDocument>
: Abstract base class that is subclassed by concrete transformations implementing anXDocument
-based transformation. LikeFlatOpcStringTransformation<TDocument>
, this class translates between formats. -
OpenXmlPackageTransformation<TDocument>
: Abstract base class that should be subclassed by concrete transformations that perform their specific operation on instances ofOpenXmlPackage
or, more specifically, instances of its subclasses. This class translates between formats. -
WordprocessingDocumentTransformation
: Abstract base class that is subclassed by concrete transformations implementing aWordprocessingDocument
-based transformation. Again, the class translates between formats. -
XslOpenXmlTransformation<TDocument>
: This class is derived fromFlatOpcStringTransformation<TDocument>
and uses an XSL stylesheet to perform the actual transformation.
Using the framework, you can basically write transforms the way you like. Are you a
Linq-to-XML person? Derive from FlatOpcDocumentTransformation<TDocument>
and implement
Transform(XDocument)
to produce a Flat OPCXDocument
while callers might use
Transform(string)
to transformstring
representations orTransform(WordprocessingDocument)
to transformWordprocessingDocument
s
without really caring about which way you implemented the actual transformation.
Do you want to leverage your XSL stylsheets? Go ahead and use XslOpenXmlTransformation
.
You're the Open XML SDK programmer? Go ahead and derive from
WordprocessingDocumentTransformation
and use the strongly typed API.
This namespace contains one class for each Open XML SDK class for which I've implemented various extensions to make my life a little easier.