Compatibility

Compatibility enumeration

指定兼容性选项的名称。

public enum Compatibility

价值观

姓名价值描述
NoTabHangInd0
NoSpaceRaiseLower1
SuppressSpBfAfterPgBrk2
WrapTrailSpaces3
PrintColBlack4
NoColumnBalance5
ConvMailMergeEsc6
SuppressTopSpacing7
UseSingleBorderforContiguousCells8
TransparentMetafiles9
ShowBreaksInFrames10
SwapBordersOddFacingPgs11
DoNotLeaveBackslashAlone12
DoNotExpandOnShiftReturn13
UlTrailSpace14
BalanceSingleByteDoubleByteWidth15
SuppressTopSpacingAtTopOfPage16
SpacingInWholePoints17
PrintBodyTextBeforeHeader18
NoLeading19
SpaceForUL20
MWSmallCaps21
SuppressTopLineSpacingWP22
TruncateFontHeightLikeWP623
SubFontBySize24
LineWrapLikeWord625
DoNotSuppressParagraphBorder26
NoExtraLineSpacing27
SuppressBottomSpacing28
WPSpaceWidth29
WPJustification30
UsePrinterMetrics31
ShapeLayoutLikeWW832
FootnoteLayoutLikeWW833
DoNotUseHtmlParagraphAutoSpacing34
AdjustLineHeightInTable35
ForgetLastTabAlignment36
AutoSpaceLikeWord9537
AlignTableRowByRow38
LayoutRawTableWidth39
LayoutTableRowsApart40
UseWord97LineBreakRules41
DoNotBreakWrappedTables42
doNotSnapToGridInCell43
SelectFldWithFirstOrLastChar44
ApplyBreakingRules45
DoNotWrapTextWithPunct46
DoNotUseEastAsianBreakRules47
UseWord2002TableStyleRules48
GrowAutofit49
UseNormalStyleForList50
DoNotUseIndentAsNumberingTabStop51
UseAltKinsokuLineBreakRules52
AllowSpaceOfSameStyleInTable53
DoNotSuppressIndentation54
DoNotAutofitConstrainedTables55
AutofitToFirstFixedWidthCell56
UnderlineTabInNumList57
DisplayHangulFixedWidth58
SplitPgBreakAndParaMark59
DoNotVertAlignCellWithSp60
DoNotBreakConstrainedForcedTable61
DoNotVertAlignInTxbx62
UseAnsiKerningPairs63
CachedColBalance64
UseFELayout65
UICompat97To200366
OverrideTableStyleFontSizeAndJustification67
DisableOpenTypeFontFormattingFeatures68
SwapInsideAndOutsideForMirrorIndentsAndRelativePositioning69
UseWord2010TableStyleRules70

例子

演示如何针对不同版本的 Microsoft Word 优化文档。

public void OptimizeFor()
{
    Document doc = new Document();

    // 该对象包含每个文档特有的广泛标志列表
    // 这使我们能够促进与旧版本 Microsoft Word 的向后兼容性。
    CompatibilityOptions options = doc.CompatibilityOptions;

    // 打印空白文档的默认设置。
    Console.WriteLine("\nDefault optimization settings:");
    PrintCompatibilityOptions(options);

    // 我们可以通过“文件”-> 在 Microsoft Word 中访问这些设置“选项”-> “高级”-> “兼容选项...”。
    doc.Save(ArtifactsDir + "CompatibilityOptions.OptimizeFor.DefaultSettings.docx");

    // 我们可以使用 OptimizeFor 方法来确保与特定 Microsoft Word 版本的最佳兼容性。
    doc.CompatibilityOptions.OptimizeFor(MsWordVersion.Word2010);
    Console.WriteLine("\nOptimized for Word 2010:");
    PrintCompatibilityOptions(options);

    doc.CompatibilityOptions.OptimizeFor(MsWordVersion.Word2000);
    Console.WriteLine("\nOptimized for Word 2000:");
    PrintCompatibilityOptions(options);
}

/// <summary>
/// 按状态对文档兼容性选项对象中的所有标志进行分组,然后打印每个组。
/// </summary>
private static void PrintCompatibilityOptions(CompatibilityOptions options)
{
    for (int i = 1; i >= 0; i--)
    {
        Console.WriteLine(Convert.ToBoolean(i) ? "\tEnabled options:" : "\tDisabled options:");
        SortedSet<string> optionNames = new SortedSet<string>();

        foreach (System.ComponentModel.PropertyDescriptor descriptor in System.ComponentModel.TypeDescriptor.GetProperties(options))
        {
            if (descriptor.PropertyType == Type.GetType("System.Boolean") && i == Convert.ToInt32(descriptor.GetValue(options)))
            {
                optionNames.Add(descriptor.Name);
            }
        }

        foreach (string s in optionNames)
        {
            Console.WriteLine($"\t\t{s}");
        }
    }
}

也可以看看