GetEffectiveValue

ListLevel.GetEffectiveValue method

报告ListLevel列表项指定 index 的对象。参数指定NumberStyle以及可选格式 string 用于Custom已指定。

public static string GetEffectiveValue(int index, NumberStyle numberStyle, 
    string customNumberStyleFormat)
范围类型描述
indexInt32列表项的索引(必须在 1 到 32767 范围内)。
numberStyleNumberStyleNumberStyleListLevel对象.
customNumberStyleFormatString可选格式字符串Custom已指定(例如“a、ç、ĝ、…”)。 在其他情况下,此参数必须是无效的或为空。

返回值

的字符串表示形式ListLevel对象,由numberStyle参数and customNumberStyleFormat参数,在列表项中由index参数.

例外

例外(健康)状况
ArgumentExceptioncustomNumberStyleFormat无效的或为空时numberStyle是自定义的。-或- customNumberStyleFormat不是无效的或为空时numberStyle是非自定义的。-或- customNumberStyleFormat无效。
ArgumentOutOfRangeException索引超出范围。

例子

展示如何获取具有自定义数字样式的列表格式。

Document doc = new Document(MyDir + "List with leading zero.docx");

ListLevel listLevel = doc.FirstSection.Body.Paragraphs[0].ListFormat.ListLevel;

string customNumberStyleFormat = string.Empty;

if (listLevel.NumberStyle == NumberStyle.Custom)
    customNumberStyleFormat = listLevel.CustomNumberStyleFormat;

Assert.AreEqual("001, 002, 003, ...", customNumberStyleFormat);

// 我们可以获取列表项指定索引的值。
Assert.AreEqual("iv", ListLevel.GetEffectiveValue(4, NumberStyle.LowercaseRoman, null));
Assert.AreEqual("005", ListLevel.GetEffectiveValue(5, NumberStyle.Custom, customNumberStyleFormat));

也可以看看