ExportListLabels
内容
[
隐藏
]HtmlSaveOptions.ExportListLabels property
控制列表标签如何输出为 HTML、MHTML 或 EPUB。 默认值为Auto.
public ExportListLabels ExportListLabels { get; set; }
例子
显示如何配置列表导出为 HTML。
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
Aspose.Words.Lists.List list = doc.Lists.Add(ListTemplate.NumberDefault);
builder.ListFormat.List = list;
builder.Writeln("Default numbered list item 1.");
builder.Writeln("Default numbered list item 2.");
builder.ListFormat.ListIndent();
builder.Writeln("Default numbered list item 3.");
builder.ListFormat.RemoveNumbers();
list = doc.Lists.Add(ListTemplate.OutlineHeadingsLegal);
builder.ListFormat.List = list;
builder.Writeln("Outline legal heading list item 1.");
builder.Writeln("Outline legal heading list item 2.");
builder.ListFormat.ListIndent();
builder.Writeln("Outline legal heading list item 3.");
builder.ListFormat.ListIndent();
builder.Writeln("Outline legal heading list item 4.");
builder.ListFormat.ListIndent();
builder.Writeln("Outline legal heading list item 5.");
builder.ListFormat.RemoveNumbers();
// 将文档保存为 HTML 时,我们可以传递一个 SaveOptions 对象
// 决定文档将使用哪些 HTML 元素来表示列表。
// 将“ExportListLabels”属性设置为“ExportListLabels.AsInlineText”
// 将通过格式化跨度来创建列表。
// 将“ExportListLabels”属性设置为“ExportListLabels.Auto”将使用 <p>标签
// 在使用 <ol> 的情况下构建列表<li>和<li>标签可能会导致格式丢失。
// 将“ExportListLabels”属性设置为“ExportListLabels.ByHtmlTags”
// 将使用 <ol>; <li>和<li>标签来构建所有列表。
HtmlSaveOptions options = new HtmlSaveOptions { ExportListLabels = exportListLabels };
doc.Save(ArtifactsDir + "HtmlSaveOptions.List.html", options);
string outDocContents = File.ReadAllText(ArtifactsDir + "HtmlSaveOptions.List.html");
switch (exportListLabels)
{
case ExportListLabels.AsInlineText:
Assert.True(outDocContents.Contains(
"<p style=\"margin-top:0pt; margin-left:72pt; margin-bottom:0pt; text-indent:-18pt; -aw-import:list-item; -aw-list-level-number:1; -aw-list-number-format:'%1.'; -aw-list-number-styles:'lowerLetter'; -aw-list-number-values:'1'; -aw-list-padding-sml:9.67pt\">" +
"<span style=\"-aw-import:ignore\">" +
"<span>a.</span>" +
"<span style=\"width:9.67pt; font:7pt 'Times New Roman'; display:inline-block; -aw-import:spaces\">       </span>" +
"</span>" +
"<span>Default numbered list item 3.</span>" +
"</p>"));
Assert.True(outDocContents.Contains(
"<p style=\"margin-top:0pt; margin-left:43.2pt; margin-bottom:0pt; text-indent:-43.2pt; -aw-import:list-item; -aw-list-level-number:3; -aw-list-number-format:'%0.%1.%2.%3'; -aw-list-number-styles:'decimal decimal decimal decimal'; -aw-list-number-values:'2 1 1 1'; -aw-list-padding-sml:10.2pt\">" +
"<span style=\"-aw-import:ignore\">" +
"<span>2.1.1.1</span>" +
"<span style=\"width:10.2pt; font:7pt 'Times New Roman'; display:inline-block; -aw-import:spaces\">       </span>" +
"</span>" +
"<span>Outline legal heading list item 5.</span>" +
"</p>"));
break;
case ExportListLabels.Auto:
Assert.True(outDocContents.Contains(
"<ol type=\"a\" style=\"margin-right:0pt; margin-left:0pt; padding-left:0pt\">" +
"<li style=\"margin-left:31.33pt; padding-left:4.67pt\">" +
"<span>Default numbered list item 3.</span>" +
"</li>" +
"</ol>"));
break;
case ExportListLabels.ByHtmlTags:
Assert.True(outDocContents.Contains(
"<ol type=\"a\" style=\"margin-right:0pt; margin-left:0pt; padding-left:0pt\">" +
"<li style=\"margin-left:31.33pt; padding-left:4.67pt\">" +
"<span>Default numbered list item 3.</span>" +
"</li>" +
"</ol>"));
break;
}
也可以看看
- enum ExportListLabels
- class HtmlSaveOptions
- 命名空间 Aspose.Words.Saving
- 部件 Aspose.Words