Compatibility

Compatibility enumeration

指定兼容性选项的名称。

public enum Compatibility

价值观

姓名 价值 描述
NoTabHangInd 0
NoSpaceRaiseLower 1
SuppressSpBfAfterPgBrk 2
WrapTrailSpaces 3
PrintColBlack 4
NoColumnBalance 5
ConvMailMergeEsc 6
SuppressTopSpacing 7
UseSingleBorderforContiguousCells 8
TransparentMetafiles 9
ShowBreaksInFrames 10
SwapBordersOddFacingPgs 11
DoNotLeaveBackslashAlone 12
DoNotExpandOnShiftReturn 13
UlTrailSpace 14
BalanceSingleByteDoubleByteWidth 15
SuppressTopSpacingAtTopOfPage 16
SpacingInWholePoints 17
PrintBodyTextBeforeHeader 18
NoLeading 19
SpaceForUL 20
MWSmallCaps 21
SuppressTopLineSpacingWP 22
TruncateFontHeightLikeWP6 23
SubFontBySize 24
LineWrapLikeWord6 25
DoNotSuppressParagraphBorder 26
NoExtraLineSpacing 27
SuppressBottomSpacing 28
WPSpaceWidth 29
WPJustification 30
UsePrinterMetrics 31
ShapeLayoutLikeWW8 32
FootnoteLayoutLikeWW8 33
DoNotUseHtmlParagraphAutoSpacing 34
AdjustLineHeightInTable 35
ForgetLastTabAlignment 36
AutoSpaceLikeWord95 37
AlignTableRowByRow 38
LayoutRawTableWidth 39
LayoutTableRowsApart 40
UseWord97LineBreakRules 41
DoNotBreakWrappedTables 42
doNotSnapToGridInCell 43
SelectFldWithFirstOrLastChar 44
ApplyBreakingRules 45
DoNotWrapTextWithPunct 46
DoNotUseEastAsianBreakRules 47
UseWord2002TableStyleRules 48
GrowAutofit 49
UseNormalStyleForList 50
DoNotUseIndentAsNumberingTabStop 51
UseAltKinsokuLineBreakRules 52
AllowSpaceOfSameStyleInTable 53
DoNotSuppressIndentation 54
DoNotAutofitConstrainedTables 55
AutofitToFirstFixedWidthCell 56
UnderlineTabInNumList 57
DisplayHangulFixedWidth 58
SplitPgBreakAndParaMark 59
DoNotVertAlignCellWithSp 60
DoNotBreakConstrainedForcedTable 61
DoNotVertAlignInTxbx 62
UseAnsiKerningPairs 63
CachedColBalance 64
UseFELayout 65
UICompat97To2003 66
OverrideTableStyleFontSizeAndJustification 67
DisableOpenTypeFontFormattingFeatures 68
SwapInsideAndOutsideForMirrorIndentsAndRelativePositioning 69
UseWord2010TableStyleRules 70

例子

展示如何针对不同版本的 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}");
        }
    }
}

也可以看看