Specify OOXML Compliance Level for Word Documents
Leave feedback
Overview
GroupDocs.Assembly for Python via .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 report keep the template’s compliance level.
Set the ooxml_compliance property to the desired compliance level (or leave it None to keep the template’s level)
Pass the LoadSaveOptions to assemble_document, before the data sources
The output document will be saved with the specified compliance level
Note
The ooxml_compliance property only applies to OOXML formats (DOCX, DOCM, DOTX, DOTM, FlatOpc, etc.) and is ignored for other file formats. When it is None (the default), the report keeps the compliance level of the template: measured with Ecma, Transitional and Strict templates, each report kept its template’s level.
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:
fromgroupdocs.assemblyimportDataSourceInfo,DocumentAssembler,FileFormat,LoadSaveOptions,OoxmlComplianceassembler=DocumentAssembler()# Create LoadSaveOptions with explicit OOXML complianceoptions=LoadSaveOptions(FileFormat.DOCX)options.ooxml_compliance=OoxmlCompliance.STRICT# or ECMA, TRANSITIONALdata={"CompanyName":"Harbor Lane Provisions","Year":2015}assembler.assemble_document("annual-summary.docx","annual-summary-report.docx",options,DataSourceInfo(data,"company"))
When ooxml_compliance is not set (default None), the report keeps the compliance level of the template:
fromgroupdocs.assemblyimportDataSourceInfo,DocumentAssembler,FileFormat,LoadSaveOptionsassembler=DocumentAssembler()# ooxml_compliance is None by default - the template's compliance is keptoptions=LoadSaveOptions(FileFormat.DOCX)data={"Title":"Delivery Schedule","Content":"Deliveries to Port Ellery run on Tuesdays and Fridays."}# The report keeps the compliance level of status-notice.docxassembler.assemble_document("status-notice.docx","status-notice-report.docx",options,DataSourceInfo(data,"document"))
The ooxml_compliance property works with all OOXML formats. The template below is a DOCX; LoadSaveOptions saves the report as DOCX, as macro-enabled DOCM and as a DOTX template:
fromgroupdocs.assemblyimportDataSourceInfo,DocumentAssembler,FileFormat,LoadSaveOptions,OoxmlComplianceassembler=DocumentAssembler()data={"Name":"Cold-pressed olive oil","Value":320}# DOCX formatdocx_options=LoadSaveOptions(FileFormat.DOCX)docx_options.ooxml_compliance=OoxmlCompliance.STRICTassembler.assemble_document("stock-card.docx","stock-card-report.docx",docx_options,DataSourceInfo(data,"item"))# DOCM format (macro-enabled)docm_options=LoadSaveOptions(FileFormat.DOCM)docm_options.ooxml_compliance=OoxmlCompliance.TRANSITIONALassembler.assemble_document("stock-card.docx","stock-card-report.docm",docm_options,DataSourceInfo(data,"item"))# DOTX format (template)dotx_options=LoadSaveOptions(FileFormat.DOTX)dotx_options.ooxml_compliance=OoxmlCompliance.STRICTassembler.assemble_document("stock-card.docx","stock-card-report.dotx",dotx_options,DataSourceInfo(data,"item"))
The following sample file is used in this example: stock-card.docx
You can also specify OOXML compliance when working with streams:
importiofromgroupdocs.assemblyimportDataSourceInfo,DocumentAssembler,FileFormat,LoadSaveOptions,OoxmlComplianceassembler=DocumentAssembler()options=LoadSaveOptions(FileFormat.DOCX)options.ooxml_compliance=OoxmlCompliance.STRICTdata={"CompanyName":"Harbor Lane Provisions","Year":2015}withopen("annual-summary.docx","rb")astemplate_stream,io.BytesIO()asoutput_stream:assembler.assemble_document(template_stream,output_stream,options,DataSourceInfo(data,"company"))withopen("annual-summary-from-stream.docx","wb")asf:f.write(output_stream.getvalue())
When explicitly set: The specified compliance level is used when saving to OOXML formats
When None (default): The report keeps the template’s compliance level (Ecma, Transitional or Strict)
For non-OOXML formats: The property is ignored (e.g., PDF, HTML, RTF)
fromgroupdocs.assemblyimportDataSourceInfo,DocumentAssembler,FileFormat,LoadSaveOptions,OoxmlComplianceassembler=DocumentAssembler()data={"Title":"Price List","Content":"Smoked gouda is 15.20 and Smoked sea salt is 3.95."}# Explicit Strict compliancestrict_options=LoadSaveOptions(FileFormat.DOCX)strict_options.ooxml_compliance=OoxmlCompliance.STRICTassembler.assemble_document("compliance-demo.docx","compliance-demo-strict.docx",strict_options,DataSourceInfo(data,"doc"))# Automatic preservation (None)auto_options=LoadSaveOptions(FileFormat.DOCX)# auto_options.ooxml_compliance is None - the template's level is keptassembler.assemble_document("compliance-demo.docx","compliance-demo-auto.docx",auto_options,DataSourceInfo(data,"doc"))# Note: For PDF output, ooxml_compliance is ignoredpdf_options=LoadSaveOptions(FileFormat.PDF)pdf_options.ooxml_compliance=OoxmlCompliance.STRICT# Ignored for PDFassembler.assemble_document("compliance-demo.docx","compliance-demo.pdf",pdf_options,DataSourceInfo(data,"doc"))
The ooxml_compliance 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: