how to read multi level list numbers in ms word(word object model)?

情到浓时终转凉″ 提交于 2019-12-23 04:28:54

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!