我正在通过word文档搜索标题和自动编号并将它们分配给元组。在MS Word中搜索标题
(Heading Style, 1.1, text)
当前我正在使用for循环来传递文档中的每个段落对象并搜索它。
for x in xrange(1, doc.Paragraphs.Count+1):#for loop to print through paragraphs
oText = doc.Paragraphs(x)
if not oText.Range.Tables.Count >0 :
results = re.match('(?P<number>(([1-3]*[A-D]*[0-9]*)(.[1-3]*[0-9])+))', oText.Range.Text)
stylematch = re.match('Heading (?P<i>\d)', oText.Style.NameLocal)
if results!= None and oText.Style != None and stylematch != None:
doccat.append((oText.Style.NameLocal, oText.Range.Text[:len(results.group('number'))],oText.Range.Text[len(results.group('number')):]))
style = oText.Style.NameLocal
是否有更有效的方法来搜索标题而不是调用和检查Word文档中的每个段落对象?
编辑:
我还要提到我用这:
doc.ConvertNumbersToText()
的自动编号转换成段落文本搜索的东西。
第二个编辑:
我不是找表的内容,但我希望能够作为一个选项。我只是在寻找标题1,2,3,4,5,6 ...等等。
它比这更糟,因为你还应该寻找基于标题样式的样式。另外,你关心大纲级别吗? – JasonPlutext