Working with Document Settings
Working with Document Settings
Beyond content, a Word document carries application-level settings – legacy compatibility
switches, hyphenation preferences, the stored mail-merge configuration, view options, and
write-protection state. Aspose.Words FOSS for .NET exposes these through the
Aspose.Words.Settings namespace and a handful of properties on Document. This page covers
each settings group and what it does and does not control.
Compatibility Options
Document.CompatibilityOptions is a CompatibilityOptions instance holding dozens of boolean
switches that reproduce specific older-Word layout and spacing behaviors – for example
GrowAutofit, UseWord2010TableStyleRules, UseWord2002TableStyleRules,
AdjustLineHeightInTable, AlignTablesRowByRow, NoExtraLineSpacing,
SuppressSpacingAtTopOfPage, SpacingInWholePoints, UseFELayout, and
BalanceSingleByteDoubleByteWidth. Set the properties you need directly to match a specific
Word version’s rendering quirks in downstream tooling that reads the document.
Hyphenation Preferences
Document.HyphenationOptions is a HyphenationOptions instance (AutoHyphenation,
ConsecutiveHyphenLimit, HyphenateCaps, HyphenationZone) that stores Word’s hyphenation
preferences for the document. These properties round-trip the request; because this edition
does not include the page-layout engine, Aspose.Words FOSS does not itself compute hyphenation
breaks – Word applies them when it opens and paginates the file.
Mail Merge Configuration
Document.MailMergeSettings is a MailMergeSettings instance that stores the mail-merge
configuration recorded in the document: MainDocumentType, CheckErrors, Destination,
DataSource, DataType, Query, ConnectString, MailSubject, MailAsAttachment,
ActiveRecord, and ViewMergedData, plus Clear() and Clone(). For external data sources
connected through Word’s Office Data Source Object mechanism, MailMergeSettings.Odso exposes
an Odso instance (DataSource, DataSourceType, TableName, ColumnDelimiter,
FirstRowContainsColumnNames) whose FieldMapDatas (OdsoFieldMapDataCollection of
OdsoFieldMapData: Name, MappedName, Column, Type) and RecipientDatas
(OdsoRecipientDataCollection of OdsoRecipientData: Active, Column, Hash, UniqueTag)
describe the field mapping and recipient list.
Document View Settings
Document.ViewOptions is a ViewOptions instance controlling how Word displays the file when
it is opened: ViewType, ZoomType, ZoomPercent, DisplayBackgroundShape,
DoNotDisplayPageBoundaries, and FormsDesign. These properties only affect Word’s own
display of the document – they have no effect on how Aspose.Words FOSS itself processes it.
Write Protection
Document.WriteProtection is a WriteProtection instance (IsWriteProtected,
ReadOnlyRecommended) with SetPassword() to establish a protection password and
ValidatePassword() to check a candidate password against it.
Measurement Units
The MeasurementUnits enum specifies the unit of measurement Word should use in its interface
for a document.
Tips and Best Practices
CompatibilityOptions.OptimizeFor(MsWordVersion)is present on the class but its implementation is not complete in this build – it throwsNotImplementedException. Set the individualCompatibilityOptionsboolean properties you need directly instead of relying onOptimizeForto apply a whole version profile at once.MailMergeSettingsandOdsostore the mail-merge configuration that was recorded in the document – reading and writing that configuration is supported, but executing a mail merge (populating fields from a live data source) is not included in this open-source edition.HyphenationOptionsandViewOptionsare both display/UI preferences that Word itself applies – do not expect callingDocument.Save()to change how the text wraps or appears based on these settings, since this edition does not include the page-layout engine.- Call
WriteProtection.SetPassword()before enablingIsWriteProtected, and useValidatePassword()to check a candidate password rather than storing or comparing the raw string yourself. CompatibilityOptions,HyphenationOptions,MailMergeSettings,ViewOptions, andWriteProtectionare all reachable directly fromDocument– there is no need to search the node tree for them.
Common Issues
| Issue | Cause | Fix |
|---|---|---|
CompatibilityOptions.OptimizeFor() throws NotImplementedException | Not implemented in this build | Set the individual CompatibilityOptions boolean properties instead |
| Mail merge doesn’t populate the document with data | MailMergeSettings only stores merge configuration; execution isn’t included in this edition | Read the stored data-source configuration and drive your own field-population logic, or use the commercial Aspose.Words for .NET |
Changing ViewOptions.ZoomPercent has no visible effect when processing the document | ViewOptions only affects Word’s display, not Aspose.Words FOSS’s own processing | Expected behavior – no fix needed |
WriteProtection.ValidatePassword() returns false unexpectedly | SetPassword() was not called first, or a different password was set | Call SetPassword() to establish the protected password before validating |
FAQ
Can I use Aspose.Words FOSS to run an actual mail merge?
No. MailMergeSettings and Odso let you read and write the merge configuration stored in a
document, but executing a mail merge – populating fields from a data source – is not
included in this open-source edition.
Does CompatibilityOptions.OptimizeFor() work?
No – it throws NotImplementedException in this build. Set the individual
CompatibilityOptions properties you need directly instead.
How do I password-protect a document against edits?
Call WriteProtection.SetPassword() on Document.WriteProtection, then set
IsWriteProtected to enable protection.
Do HyphenationOptions and ViewOptions change how the document is laid out?
No. Both are stored preferences that Microsoft Word applies when it opens and displays the file. This edition does not include the page-layout engine, so these settings pass through without Aspose.Words FOSS itself computing layout from them.
API Reference Summary
| Class / Enum | Description |
|---|---|
CompatibilityOptions | Legacy Word-version layout/spacing switches, via Document.CompatibilityOptions |
Compatibility | Enum naming the individual compatibility options |
MsWordVersion | Word version values used by CompatibilityOptions.OptimizeFor() |
HyphenationOptions | Hyphenation preferences, via Document.HyphenationOptions |
MailMergeSettings | Stored mail-merge configuration, via Document.MailMergeSettings |
Odso | Office Data Source Object connection settings for mail merge |
OdsoFieldMapData / OdsoFieldMapDataCollection | Column-to-merge-field mapping for an ODSO data source |
OdsoRecipientData / OdsoRecipientDataCollection | Per-recipient inclusion/exclusion state for a mail merge |
ViewOptions | Word display preferences (zoom, formatting marks), via Document.ViewOptions |
WriteProtection | Document write-protection state, via Document.WriteProtection |
MeasurementUnits | Unit of measurement Word should use in its interface |