根据自定义标签在Aspose Word中选择目录内容

huangapple 未分类评论57阅读模式
英文:

Selecting TOC content as per custom tag in Aspose word

问题

我正在使用 Aspose Word 18.9。我们知道默认插入目录的方法是:

    builder.InsertTableOfContents("\\o \"1-3\" \\h \\z \\u");

这里只有 <code>H1-H3</code> 标签会被考虑用于目录。但是标题标签会在内容中创建额外的空格,这是我不想要的。

因此,我想要使用用户自定义的标签作为目录。目前我已经创建了用户自定义的标签 <code>toc</code>。

例如:

    <toc>Heading 1</toc>
    <toc>Heading 2</toc>

我希望使用这个标签来构建目录。

有没有什么方法可以实现这样的效果?

请帮忙!
英文:

I am using Aspose word 18.9. We know that the default way to insert Table of content is :

builder.InsertTableOfContents(&quot;\\o \&quot;1-3\&quot; \\h \\z \\u&quot;);

Here Only <code>H1-H3</code> tags will be considered for TOC. But Header tags create extra spaces in the content which I don't want.

So I want to use user-defined tag for TOC. Currently I have created user-defined tag <code>toc</code>.

For example:

&lt;toc&gt;Heading 1&lt;/toc&gt;
&lt;toc&gt;Heading 2&lt;/toc&gt;

I want this tag to be used to build the TOC.

Is there any way to do so?

Please help!

答案1

得分: 0

@Newinjava 我认为在你的情况下,你可以使用 TC(目录项) 字段,而不是你的自定义标签。然后,你可以使用 ''\f EntryIdentifier'' 来构建 TOC(目录)
例如,你可以使用以下开关插入目录:

{ TOC \o &quot;1-3&quot; \h \z \u \f mycoolid } 

然后,你可以像这样插入 TC 字段来构建目录:

{ TC  &quot;一级标题&quot; \f mycoolid \l 1 }
{ TC  &quot;二级标题&quot; \f mycoolid \l 2 }
{ TC  &quot;三级标题&quot; \f mycoolid \l 3 }

你可以使用 DocumentBuilder.InsertField 方法或者使用 MS Word 来以编程方式插入这些字段。

英文:

@Newinjava I think, in your case, you can use TC (Table of Contents Entry) field instead of your custom tags. Then you can use '\f EntryIdentifier' To build TOC.
For example you insert TOC with the following switches:

{ TOC \o &quot;1-3&quot; \h \z \u \f mycoolid } 

Then you inset TC fields like this to build TOC

{ TC  &quot;first level&quot; \f mycoolid \l 1 }
{ TC  &quot;second level&quot; \f mycoolid \l 2 }
{ TC  &quot;third level&quot; \f mycoolid \l 3 }

You can insert such fields programmatically using DocumentBuilder.InsertField method or using MS Word.

huangapple
  • 本文由 发表于 2020年7月27日 19:37:45
  • 转载请务必保留本文链接:https://java.coder-hub.com/63114511.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定