CompatibilityOptions

CompatibilityOptions class

包含兼容性选项(即在兼容性 标签选项对话框)。

要了解更多信息,请访问检测文件格式并检查格式兼容性文档文章。

public class CompatibilityOptions

特性

姓名描述
AdjustLineHeightInTable { get; set; }将文档网格线间距添加到表格单元格中的线条。
AlignTablesRowByRow { get; set; }独立对齐表格行。
AllowSpaceOfSameStyleInTable { get; set; }允许表格中段落的上下文间距。
ApplyBreakingRules { get; set; }使用旧版埃塞俄比亚语和阿姆哈拉语换行规则。
AutofitToFirstFixedWidthCell { get; set; }允许表格列超出组成单元格的首选宽度。
AutoSpaceLikeWord95 { get; set; }模拟 Word 95 全角字符间距。
BalanceSingleByteDoubleByteWidth { get; set; }平衡单字节和双字节字符。
CachedColBalance { get; set; }使用缓存的段落信息进行列平衡。
ConvMailMergeEsc { get; set; }将反斜杠引号分隔符视为两个引号。
DisableOpenTypeFontFormattingFeatures { get; set; }指定禁用 OpenType 字体格式化功能。
DisplayHangulFixedWidth { get; set; }始终对韩文字符使用固定宽度。
DoNotAutofitConstrainedTables { get; set; }不自动调整表格以适应环绕对象。
DoNotBreakConstrainedForcedTable { get; set; }不要破坏浮动表格周围的表格行。
DoNotBreakWrappedTables { get; set; }不允许浮动表格跨页。
DoNotExpandShiftReturn { get; set; }不要对齐以软换行符结尾的行。
DoNotLeaveBackslashAlone { get; set; }输入时将反斜杠转换为日元符号。
DoNotSnapToGridInCell { get; set; }不要在带有对象的表格单元格中捕捉到文档网格。
DoNotSuppressIndentation { get; set; }计算段落缩进时不要忽略浮动对象。
DoNotSuppressParagraphBorders { get; set; }不抑制框架旁边的段落边框。
DoNotUseEastAsianBreakRules { get; set; }使用文档网格时请勿压缩可压缩字符。
DoNotUseHTMLParagraphAutoSpacing { get; set; }使用固定段落间距进行 HTML 自动设置。
DoNotUseIndentAsNumberingTabStop { get; set; }编号后创建制表位时忽略悬挂缩进。
DoNotVertAlignCellWithSp { get; set; }不要垂直对齐包含浮动对象的单元格。
DoNotVertAlignInTxbx { get; set; }忽略文本框中的垂直对齐。
DoNotWrapTextWithPunct { get; set; }不允许使用带有字符网格的悬挂标点符号。
FootnoteLayoutLikeWW8 { get; set; }模拟 Word 6.x/95/97 脚注位置。
ForgetLastTabAlignment { get; set; }如果段落未左对齐,则对齐段落时忽略最后一个制表位的宽度。
GrowAutofit { get; set; }允许表格自动适应页边距。
LayoutRawTableWidth { get; set; }在决定表格是否应包裹浮动对象时忽略表格前的空间。
LayoutTableRowsApart { get; set; }允许表格行独立包装内联对象。
LineWrapLikeWord6 { get; set; }模拟 Word 6.0 东亚文本换行。
MWSmallCaps { get; set; }模拟 Macintosh 小型大写字母格式的 Word 5.x。
NoColumnBalance { get; set; }不要平衡同一部分内的文本列。
NoExtraLineSpacing { get; set; }不要将内容置于具有精确行高的行的中心。
NoLeading { get; set; }不要在文本行之间添加行距。
NoSpaceRaiseLower { get; set; }不要增加升高/降低文本的行高。
NoTabHangInd { get; set; }不为悬挂缩进创建自定义制表位。
OverrideTableStyleFontSizeAndJustification { get; set; }指定如何评估文档的样式层次结构。
PrintBodyTextBeforeHeader { get; set; }在页眉/页脚内容之前打印正文。
PrintColBlack { get; set; }将颜色打印为黑白,无抖动。
SelectFldWithFirstOrLastChar { get; set; }当选择第一个或最后一个字符时选择字段。
ShapeLayoutLikeWW8 { get; set; }模拟 Word 97 文本环绕浮动对象。
ShowBreaksInFrames { get; set; }显示框架中的分页符/分栏符。
SpaceForUL { get; set; }在基线下方添加额外空间,用于为东亚文本添加下划线。
SpacingInWholePoints { get; set; }仅按整数点扩展/压缩文本。
SplitPgBreakAndParaMark { get; set; }始终将段落标记移动到分页符后的页面。
SubFontBySize { get; set; }字体替换时增加字体大小的优先级。
SuppressBottomSpacing { get; set; }忽略页面最后一行的精确行高。
SuppressSpacingAtTopOfPage { get; set; }忽略页面第一行的最小行高。
SuppressSpBfAfterPgBrk { get; set; }分页后第一行前不要使用空格。
SuppressTopSpacing { get; set; }忽略页面第一行的最小行高和精确行高。
SuppressTopSpacingWP { get; set; }模拟 WordPerfect 5.x 行距。
SwapBordersFacingPgs { get; set; }交换奇数页的段落边框。
SwapInsideAndOutsideForMirrorIndentsAndRelativePositioning { get; set; }指定交换镜像缩进和相对定位的内部和外部。
TransparentMetafiles { get; set; }指定不空白图元文件图片后面的区域。
TruncateFontHeightsLikeWP6 { get; set; }模拟 WordPerfect 6.x 字体高度计算。
UICompat97To2003 { get; set; }True 表示禁用与 Word97-2003 不兼容的 UI 功能。 默认值为错误的.
UlTrailSpace { get; set; }为所有尾随空格添加下划线。
UnderlineTabInNumList { get; set; }下划线跟在字符后面,数字后面。
UseAltKinsokuLineBreakRules { get; set; }使用备用的东亚换行规则集。
UseAnsiKerningPairs { get; set; }使用字体中的 ANSI 字距调整对。
UseFELayout { get; set; }请勿绕过东亚/复杂脚本布局代码。
UseNormalStyleForList { get; set; }不自动将列表段落样式应用于项目符号/编号文本。
UsePrinterMetrics { get; set; }使用打印机指标显示文档。
UseSingleBorderforContiguousCells { get; set; }使用简化规则解决表格边框冲突。
UseWord2002TableStyleRules { get; set; }模拟 Word 2002 表格样式规则。
UseWord2010TableStyleRules { get; set; }指定使用 Word2010 表格样式规则。
UseWord97LineBreakRules { get; set; }模拟 Word 97 东亚换行。
WPJustification { get; set; }模拟 WordPerfect 6.x 段落对齐。
WPSpaceWidth { get; set; }指定是否像在 WordPerfect 5.x 中一样设置空格的宽度。
WrapTrailSpaces { get; set; }换行尾随空格。

方法

姓名描述
OptimizeFor(MsWordVersion)允许优化文档内容以及默认 Aspose.Words 行为以适应特定版本的 MS Word。

例子

展示如何垂直对齐文本框的文本内容。

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

Shape shape = builder.InsertShape(ShapeType.TextBox, 200, 200);

// 将“VerticalAnchor”属性设置为“TextBoxAnchor.Top”
// 将此文本框中的文本与形状的顶部对齐。
// 将“VerticalAnchor”属性设置为“TextBoxAnchor.Middle”
// 将此文本框中的文本与形状的中心对齐。
// 将“VerticalAnchor”属性设置为“TextBoxAnchor.Bottom”
// 将此文本框中的文本与形状的底部对齐。
shape.TextBox.VerticalAnchor = verticalAnchor;

builder.MoveTo(shape.FirstParagraph);
builder.Write("Hello world!");

// 从 Microsoft Word 2007 开始,文本框内的文本可以垂直对齐。
doc.CompatibilityOptions.OptimizeFor(MsWordVersion.Word2007);
doc.Save(ArtifactsDir + "Shape.VerticalAnchor.docx");

展示如何设置已保存文档所遵循的 OOXML 合规性规范。

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

// 如果我们配置兼容性选项以符合 Microsoft Word 2003,
// 插入图像将使用 VML 定义其形状。
doc.CompatibilityOptions.OptimizeFor(MsWordVersion.Word2003);
builder.InsertImage(ImageDir + "Transparent background logo.png");

Assert.AreEqual(ShapeMarkupLanguage.Vml, ((Shape)doc.GetChild(NodeType.Shape, 0, true)).MarkupLanguage);

// “ISO/IEC 29500:2008” OOXML 标准不支持 VML 形状。
// 如果我们将 SaveOptions 对象的“Compliance”属性设置为“OoxmlCompliance.Iso29500_2008_Strict”,
 // 我们在传递此对象时保存的任何文档都必须遵循该标准。
OoxmlSaveOptions saveOptions = new OoxmlSaveOptions
{
    Compliance = OoxmlCompliance.Iso29500_2008_Strict,
    SaveFormat = SaveFormat.Docx
};

doc.Save(ArtifactsDir + "OoxmlSaveOptions.Iso29500Strict.docx", saveOptions);

// 我们保存的文档使用 DML 定义形状以遵守“ISO/IEC 29500:2008”OOXML 标准。
doc = new Document(ArtifactsDir + "OoxmlSaveOptions.Iso29500Strict.docx");

Assert.AreEqual(ShapeMarkupLanguage.Dml, ((Shape)doc.GetChild(NodeType.Shape, 0, true)).MarkupLanguage);

展示如何针对不同版本的 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)
{
    IList<string> enabledOptions = new List<string>();
    IList<string> disabledOptions = new List<string>();
    AddOptionName(options.AdjustLineHeightInTable, "AdjustLineHeightInTable", enabledOptions, disabledOptions);
    AddOptionName(options.AlignTablesRowByRow, "AlignTablesRowByRow", enabledOptions, disabledOptions);
    AddOptionName(options.AllowSpaceOfSameStyleInTable, "AllowSpaceOfSameStyleInTable", enabledOptions, disabledOptions);
    AddOptionName(options.ApplyBreakingRules, "ApplyBreakingRules", enabledOptions, disabledOptions);
    AddOptionName(options.AutoSpaceLikeWord95, "AutoSpaceLikeWord95", enabledOptions, disabledOptions);
    AddOptionName(options.AutofitToFirstFixedWidthCell, "AutofitToFirstFixedWidthCell", enabledOptions, disabledOptions);
    AddOptionName(options.BalanceSingleByteDoubleByteWidth, "BalanceSingleByteDoubleByteWidth", enabledOptions, disabledOptions);
    AddOptionName(options.CachedColBalance, "CachedColBalance", enabledOptions, disabledOptions);
    AddOptionName(options.ConvMailMergeEsc, "ConvMailMergeEsc", enabledOptions, disabledOptions);
    AddOptionName(options.DisableOpenTypeFontFormattingFeatures, "DisableOpenTypeFontFormattingFeatures", enabledOptions, disabledOptions);
    AddOptionName(options.DisplayHangulFixedWidth, "DisplayHangulFixedWidth", enabledOptions, disabledOptions);
    AddOptionName(options.DoNotAutofitConstrainedTables, "DoNotAutofitConstrainedTables", enabledOptions, disabledOptions);
    AddOptionName(options.DoNotBreakConstrainedForcedTable, "DoNotBreakConstrainedForcedTable", enabledOptions, disabledOptions);
    AddOptionName(options.DoNotBreakWrappedTables, "DoNotBreakWrappedTables", enabledOptions, disabledOptions);
    AddOptionName(options.DoNotExpandShiftReturn, "DoNotExpandShiftReturn", enabledOptions, disabledOptions);
    AddOptionName(options.DoNotLeaveBackslashAlone, "DoNotLeaveBackslashAlone", enabledOptions, disabledOptions);
    AddOptionName(options.DoNotSnapToGridInCell, "DoNotSnapToGridInCell", enabledOptions, disabledOptions);
    AddOptionName(options.DoNotSuppressIndentation, "DoNotSnapToGridInCell", enabledOptions, disabledOptions);
    AddOptionName(options.DoNotSuppressParagraphBorders, "DoNotSuppressParagraphBorders", enabledOptions, disabledOptions);
    AddOptionName(options.DoNotUseEastAsianBreakRules, "DoNotUseEastAsianBreakRules", enabledOptions, disabledOptions);
    AddOptionName(options.DoNotUseHTMLParagraphAutoSpacing, "DoNotUseHTMLParagraphAutoSpacing", enabledOptions, disabledOptions);
    AddOptionName(options.DoNotUseIndentAsNumberingTabStop, "DoNotUseIndentAsNumberingTabStop", enabledOptions, disabledOptions);
    AddOptionName(options.DoNotVertAlignCellWithSp, "DoNotVertAlignCellWithSp", enabledOptions, disabledOptions);
    AddOptionName(options.DoNotVertAlignInTxbx, "DoNotVertAlignInTxbx", enabledOptions, disabledOptions);
    AddOptionName(options.DoNotWrapTextWithPunct, "DoNotWrapTextWithPunct", enabledOptions, disabledOptions);
    AddOptionName(options.FootnoteLayoutLikeWW8, "FootnoteLayoutLikeWW8", enabledOptions, disabledOptions);
    AddOptionName(options.ForgetLastTabAlignment, "ForgetLastTabAlignment", enabledOptions, disabledOptions);
    AddOptionName(options.GrowAutofit, "GrowAutofit", enabledOptions, disabledOptions);
    AddOptionName(options.LayoutRawTableWidth, "LayoutRawTableWidth", enabledOptions, disabledOptions);
    AddOptionName(options.LayoutTableRowsApart, "LayoutTableRowsApart", enabledOptions, disabledOptions);
    AddOptionName(options.LineWrapLikeWord6, "LineWrapLikeWord6", enabledOptions, disabledOptions);
    AddOptionName(options.MWSmallCaps, "MWSmallCaps", enabledOptions, disabledOptions);
    AddOptionName(options.NoColumnBalance, "NoColumnBalance", enabledOptions, disabledOptions);
    AddOptionName(options.NoExtraLineSpacing, "NoExtraLineSpacing", enabledOptions, disabledOptions);
    AddOptionName(options.NoLeading, "NoLeading", enabledOptions, disabledOptions);
    AddOptionName(options.NoSpaceRaiseLower, "NoSpaceRaiseLower", enabledOptions, disabledOptions);
    AddOptionName(options.NoTabHangInd, "NoTabHangInd", enabledOptions, disabledOptions);
    AddOptionName(options.OverrideTableStyleFontSizeAndJustification, "OverrideTableStyleFontSizeAndJustification", enabledOptions, disabledOptions);
    AddOptionName(options.PrintBodyTextBeforeHeader, "PrintBodyTextBeforeHeader", enabledOptions, disabledOptions);
    AddOptionName(options.PrintColBlack, "PrintColBlack", enabledOptions, disabledOptions);
    AddOptionName(options.SelectFldWithFirstOrLastChar, "SelectFldWithFirstOrLastChar", enabledOptions, disabledOptions);
    AddOptionName(options.ShapeLayoutLikeWW8, "ShapeLayoutLikeWW8", enabledOptions, disabledOptions);
    AddOptionName(options.ShowBreaksInFrames, "ShowBreaksInFrames", enabledOptions, disabledOptions);
    AddOptionName(options.SpaceForUL, "SpaceForUL", enabledOptions, disabledOptions);
    AddOptionName(options.SpacingInWholePoints, "SpacingInWholePoints", enabledOptions, disabledOptions);
    AddOptionName(options.SplitPgBreakAndParaMark, "SplitPgBreakAndParaMark", enabledOptions, disabledOptions);
    AddOptionName(options.SubFontBySize, "SubFontBySize", enabledOptions, disabledOptions);
    AddOptionName(options.SuppressBottomSpacing, "SuppressBottomSpacing", enabledOptions, disabledOptions);
    AddOptionName(options.SuppressSpBfAfterPgBrk, "SuppressSpBfAfterPgBrk", enabledOptions, disabledOptions);
    AddOptionName(options.SuppressSpacingAtTopOfPage, "SuppressSpacingAtTopOfPage", enabledOptions, disabledOptions);
    AddOptionName(options.SuppressTopSpacing, "SuppressTopSpacing", enabledOptions, disabledOptions);
    AddOptionName(options.SuppressTopSpacingWP, "SuppressTopSpacingWP", enabledOptions, disabledOptions);
    AddOptionName(options.SwapBordersFacingPgs, "SwapBordersFacingPgs", enabledOptions, disabledOptions);
    AddOptionName(options.SwapInsideAndOutsideForMirrorIndentsAndRelativePositioning, "SwapInsideAndOutsideForMirrorIndentsAndRelativePositioning", enabledOptions, disabledOptions);
    AddOptionName(options.TransparentMetafiles, "TransparentMetafiles", enabledOptions, disabledOptions);
    AddOptionName(options.TruncateFontHeightsLikeWP6, "TruncateFontHeightsLikeWP6", enabledOptions, disabledOptions);
    AddOptionName(options.UICompat97To2003, "UICompat97To2003", enabledOptions, disabledOptions);
    AddOptionName(options.UlTrailSpace, "UlTrailSpace", enabledOptions, disabledOptions);
    AddOptionName(options.UnderlineTabInNumList, "UnderlineTabInNumList", enabledOptions, disabledOptions);
    AddOptionName(options.UseAltKinsokuLineBreakRules, "UseAltKinsokuLineBreakRules", enabledOptions, disabledOptions);
    AddOptionName(options.UseAnsiKerningPairs, "UseAnsiKerningPairs", enabledOptions, disabledOptions);
    AddOptionName(options.UseFELayout, "UseFELayout", enabledOptions, disabledOptions);
    AddOptionName(options.UseNormalStyleForList, "UseNormalStyleForList", enabledOptions, disabledOptions);
    AddOptionName(options.UsePrinterMetrics, "UsePrinterMetrics", enabledOptions, disabledOptions);
    AddOptionName(options.UseSingleBorderforContiguousCells, "UseSingleBorderforContiguousCells", enabledOptions, disabledOptions);
    AddOptionName(options.UseWord2002TableStyleRules, "UseWord2002TableStyleRules", enabledOptions, disabledOptions);
    AddOptionName(options.UseWord2010TableStyleRules, "UseWord2010TableStyleRules", enabledOptions, disabledOptions);
    AddOptionName(options.UseWord97LineBreakRules, "UseWord97LineBreakRules", enabledOptions, disabledOptions);
    AddOptionName(options.WPJustification, "WPJustification", enabledOptions, disabledOptions);
    AddOptionName(options.WPSpaceWidth, "WPSpaceWidth", enabledOptions, disabledOptions);
    AddOptionName(options.WrapTrailSpaces, "WrapTrailSpaces", enabledOptions, disabledOptions);
    Console.WriteLine("\tEnabled options:");
    foreach (string optionName in enabledOptions)
        Console.WriteLine($"\t\t{optionName}");
    Console.WriteLine("\tDisabled options:");
    foreach (string optionName in disabledOptions)
        Console.WriteLine($"\t\t{optionName}");
}

private static void AddOptionName(Boolean option, String optionName, IList<string> enabledOptions, IList<string> disabledOptions)
{
    if (option)
        enabledOptions.Add(optionName);
    else
        disabledOptions.Add(optionName);
}

也可以看看