问题
I want to read multi-level list formats in word.
for example,if list is
1.abc
2.def
a.ghi
b.jkl
with the range object for ghi,
i want to get the list number string as,
2.a. ghi
i got to know that Listformat.ListLevelNumber gives the list level.
But not getting any property to get the list numbering in this form.
is there any property?
or,any work around to get this?
or, any concept that can help me?
i have gone through some topics in msdn that i felt like may help.
and i am having range object.
回答1:
i got one soution to this by dividing the range into paragraph and then using the listLevelnumber to iterate backward till i reach the paragraph with 1 less listlevelNumber, representing the last list in the higher level list.there i accessed the ListString.repeated it till i reach the top level list. The code in python is,
text=Range.ListFormat.ListString+str(Range.text)
level=Range.ListFormat.ListLevelNumber
lstr=""
if level > 1:
p=Range.Paragraphs.First
while level >1 :
while p.Range.ListFormat.ListLevelNumber == level :
p=p.Previous(1)
lstr=p.Range.ListFormat.ListString+lstr
level=level-1
if lstr:
text=lstr+text
lstr contained the list prefix i wanted to add,to get the string representing the full nested form. This solution that i got is based on the fact that all list items are different paragraphs.
来源:https://stackoverflow.com/questions/19634350/how-to-read-multi-level-list-numbers-in-ms-wordword-object-model