使用相同的多级列表样式的多种标题样式 [英] Multiple heading styles using the same multilevel list style

查看:255
本文介绍了使用相同的多级列表样式的多种标题样式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图将编号分配给Word中的多种标题样式,以便获得如下内容:

I'm trying to assign numbering to multiple heading styles in Word, so that I get content like the following:

6. <Heading 1>
6.1. <Heading 2>
6.1.1. <Heading 3>
6.2. <Heading 2>
6.2.1. <Heading 3>
6.3. <Heading 2>

通过使用第二种多级编号样式(忽略无"),您可以在标准Word中非常容易地做到这一点,该样式看起来像这样:

You can do this pretty easily in standard Word by using the second multilevel numbering style (ignoring 'None'), the one that looks like this:

1.
1.1.
1.1.1.

但是我试图通过在代码中应用第二种多级编号样式来动态地做到这一点,结果是这样的:

But I'm trying to do this dynamically, by applying the second multilevel numbering style in code, and it comes out like this:

6. <Heading 1>
1.1 <Heading 2>
1.1.1 <Heading 3>
7. <Heading 1>
1.2 <Heading 2>
1.1.2 <Heading 3>

如果我在此之后手动应用第二种多级编号样式,它将更改为所需的输出.

If I apply the second multilevel numbering style manually after this, it changes to the desired output.

这是我的代码(有点简化,但不多).

Here is my code (a bit simplified but not by much).

ListGallery gallery = doc.Application.ListGalleries[WdListGalleryType.wdOutlineNumberGallery];
ListTemplate numberedTemplate = gallery.ListTemplates[2];
for (int i = 1; i < 10; i++)
{
  Style style = doc.Styles["Heading " + i];
  style.LinkToListTemplate(numberedTemplate, i);
}

推荐答案

使用ListGalleries不可靠/不可靠.对于索引(从用户界面的列表中选择数字格式),您不能确保列表的内容始终相同-缺点很明显.

Using ListGalleries is not reliable/robust. In the case of indexes (choosing a number format from the list in the UI) you can't be sure the content of the list is always the same - that drawback is obvious.

内置画廊的问题(例如您正在使用的)是,这个特定画廊有一个错误"(就像第一次发布时在UI中所做的那样):第2级和第3级没有激活之后重新启动列表"设置,因此您将获得所描述的行为.

The problem with the built-in galleries, such as you're using, is that this particular one has a "bug" (as it did in the UI when first released): levels 2 and 3 don't have the "Restart List After" setting activated, so you get the described behavior.

因此,最好在创建自定义列表时记录宏,最好使用轮廓编号菜单中的定义新列表样式".然后,您可以在任何地方使用该代码.

For that reason, it's better to record a macro while creating a custom list, preferably using "Define New List Style" from the outline numbering menu. You can then use the code anywhere.

定义一个命名列表样式将为您提供一个命名列表模板,这意味着它可以重复使用和直接管理. (在您的代码中,您使用索引值来引用ListTemplate,如果您要使用的那个不是集合中的第二个,则可能会出错.)

Defining a named List Style will give you a named List Template, which means it can be re-used and managed directly. (In your code you use an index value to reference a ListTemplate, which can go wrong if the one you intend to use is not the second one in the collection.)

这篇关于使用相同的多级列表样式的多种标题样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆