Specify OOXML Compliance Level for Word Documents

Overview

GroupDocs.Assembly for .NET allows you to control the OOXML compliance level when saving Word documents to OOXML formats (DOCX, DOCM, DOTX, DOTM, FlatOpc, etc.). You can explicitly specify the compliance level or let the system automatically preserve the original document’s compliance level.

The main classes involved are:

Here are the steps to specify OOXML compliance:

  • Create LoadSaveOptions for your output format
  • Set the OoxmlCompliance property to the desired compliance level (or leave null for automatic preservation)
  • Use DocumentAssembler with the LoadSaveOptions to assemble the document
  • The output document will be saved with the specified compliance level
Note
The OoxmlCompliance property only applies to OOXML formats (DOCX, DOCM, DOTX, DOTM, FlatOpc, etc.) and is ignored for other file formats. When set to null (default), the system automatically preserves the original document’s compliance level if it was Transitional, otherwise uses Strict compliance.

Available OOXML Compliance Levels

The OoxmlCompliance enumeration provides three compliance levels:

  • Ecma: Specifies ECMA-376 compliance level
  • Transitional: Specifies ISO/IEC 29500:2008 Transitional compliance level (commonly used for compatibility)
  • Strict: Specifies ISO/IEC 29500:2008 Strict compliance level (fully compliant with the standard)

Specify Explicit OOXML Compliance Level

You can explicitly set the OOXML compliance level when assembling a document:

using GroupDocs.Assembly;

public static void SpecifyExplicitCompliance()
{
    DocumentAssembler assembler = new DocumentAssembler();

    // Create LoadSaveOptions with explicit OOXML compliance
    var options = new LoadSaveOptions(FileFormat.Docx);
    options.OoxmlCompliance = OoxmlCompliance.Strict; // or Ecma, Transitional

    var data = new { CompanyName = "ABC Corp", Year = 2024 };
    
    assembler.AssembleDocument("Template.docx", "Output.docx", options,
        new DataSourceInfo(data, "company"));
}

Use Transitional Compliance

For maximum compatibility with older Office versions, use Transitional compliance:

using GroupDocs.Assembly;

public static void UseTransitionalCompliance()
{
    DocumentAssembler assembler = new DocumentAssembler();

    var options = new LoadSaveOptions(FileFormat.Docx);
    options.OoxmlCompliance = OoxmlCompliance.Transitional;

    var data = new { CustomerName = "John Doe", OrderNumber = "ORD-12345" };
    
    assembler.AssembleDocument("Template.docx", "Output.docx", options,
        new DataSourceInfo(data, "order"));
}

Use Ecma Compliance

For ECMA-376 standard compliance:

using GroupDocs.Assembly;

public static void UseEcmaCompliance()
{
    DocumentAssembler assembler = new DocumentAssembler();

    var options = new LoadSaveOptions(FileFormat.Docx);
    options.OoxmlCompliance = OoxmlCompliance.Ecma;

    var data = new { ReportTitle = "Monthly Report", Month = "January 2024" };
    
    assembler.AssembleDocument("Template.docx", "Output.docx", options,
        new DataSourceInfo(data, "report"));
}

Automatic Preservation of Original Compliance

When OoxmlCompliance is not explicitly set (default null), the system automatically preserves the original document’s compliance level if it was Transitional:

using GroupDocs.Assembly;

public static void PreserveOriginalCompliance()
{
    DocumentAssembler assembler = new DocumentAssembler();

    // OoxmlCompliance is null by default - original compliance will be preserved
    var options = new LoadSaveOptions(FileFormat.Docx);
    // options.OoxmlCompliance is null - automatic preservation

    var data = new { Title = "Document Title", Content = "Document content" };
    
    // Output document will maintain Transitional compliance from template if it was Transitional
    assembler.AssembleDocument("Template_Transitional.docx", "Output.docx", options,
        new DataSourceInfo(data, "document"));
}

Using with Different OOXML Formats

The OoxmlCompliance property works with all OOXML formats:

using GroupDocs.Assembly;

public static void UseWithDifferentFormats()
{
    DocumentAssembler assembler = new DocumentAssembler();
    var data = new { Name = "Test Document", Value = 100 };
    
    // DOCX format
    var docxOptions = new LoadSaveOptions(FileFormat.Docx);
    docxOptions.OoxmlCompliance = OoxmlCompliance.Strict;
    assembler.AssembleDocument("Template.docx", "Output.docx", docxOptions,
        new DataSourceInfo(data, "item"));
    
    // DOCM format (macro-enabled)
    var docmOptions = new LoadSaveOptions(FileFormat.Docm);
    docmOptions.OoxmlCompliance = OoxmlCompliance.Transitional;
    assembler.AssembleDocument("Template.docm", "Output.docm", docmOptions,
        new DataSourceInfo(data, "item"));
    
    // DOTX format (template)
    var dotxOptions = new LoadSaveOptions(FileFormat.Dotx);
    dotxOptions.OoxmlCompliance = OoxmlCompliance.Strict;
    assembler.AssembleDocument("Template.dotx", "Output.dotx", dotxOptions,
        new DataSourceInfo(data, "item"));
}

Using with Streams

You can also specify OOXML compliance when working with streams:

using GroupDocs.Assembly;
using System.IO;

public static void UseComplianceWithStreams()
{
    DocumentAssembler assembler = new DocumentAssembler();

    var options = new LoadSaveOptions(FileFormat.Docx);
    options.OoxmlCompliance = OoxmlCompliance.Strict;

    var data = new { Company = "My Company", Year = 2024 };
    
    using (FileStream templateStream = new FileStream("Template.docx", FileMode.Open))
    using (FileStream outputStream = new FileStream("Output.docx", FileMode.Create))
    {
        assembler.AssembleDocument(templateStream, outputStream, options,
            new DataSourceInfo(data, "company"));
    }
}

Compliance Level Behavior

Understanding how compliance levels work:

  • When explicitly set: The specified compliance level is used when saving to OOXML formats
  • When null (default):
    • If the original document had Transitional compliance, it is preserved
    • Otherwise, Strict compliance is used
  • For non-OOXML formats: The property is ignored (e.g., PDF, HTML, RTF)
using GroupDocs.Assembly;

public static void DemonstrateComplianceBehavior()
{
    DocumentAssembler assembler = new DocumentAssembler();
    var data = new { Title = "Test", Content = "Content" };
    
    // Explicit Strict compliance
    var strictOptions = new LoadSaveOptions(FileFormat.Docx);
    strictOptions.OoxmlCompliance = OoxmlCompliance.Strict;
    assembler.AssembleDocument("Template.docx", "Output_Strict.docx", strictOptions,
        new DataSourceInfo(data, "doc"));
    
    // Automatic preservation (null)
    var autoOptions = new LoadSaveOptions(FileFormat.Docx);
    // autoOptions.OoxmlCompliance is null - will preserve if Transitional
    assembler.AssembleDocument("Template.docx", "Output_Auto.docx", autoOptions,
        new DataSourceInfo(data, "doc"));
    
    // Note: For PDF output, OoxmlCompliance is ignored
    var pdfOptions = new LoadSaveOptions(FileFormat.Pdf);
    pdfOptions.OoxmlCompliance = OoxmlCompliance.Strict; // Ignored for PDF
    assembler.AssembleDocument("Template.docx", "Output.pdf", pdfOptions,
        new DataSourceInfo(data, "doc"));
}
Warning
The OoxmlCompliance property only affects OOXML formats. When saving to other formats like PDF, HTML, or RTF, this property is ignored. The compliance level is determined by the output format, not the template format.

Advanced Usage Topics

To learn more about format-specific options, document conversion settings, and advanced compliance handling, please refer to the advanced usage section.

More resources

GitHub Examples

You may easily run the code above and see the feature in action in our GitHub examples:

Free Online Apps

Along with the full-featured .NET library, we provide simple but powerful free online apps.

To assemble documents from templates and data sources, you can use the online apps from the GroupDocs.Assembly App Product Family.

Close
Loading

Analyzing your prompt, please hold on...

An error occurred while retrieving the results. Please refresh the page and try again.