openoffice获取当前文档的段落和表格总数

    工作期间需要统计出当前文档所有段落和表格,摘出其中一段宏:


Sub enumerateParagraphsAndTable
  Dim oEnum              'com.sun.star.container.XEnumerationAccess
  Dim oPar               'Paragraph of some sort
  Dim nPars As Integer   'Number of paragraphs
  Dim nTables As Integer 'Number of tables

  'ThisComponent refers to the current OOo document
  'Text is a property of ThisComponent for a text document
  ' The getText() object method returns the same thing.
  ' createEnumeration() is an object method.
  oEnum = ThisComponent.Text.createEnumeration()
  Do While oEnum.hasMoreElements()
    oPar = oEnum.nextElement()

    ' The returned paragraph will be a paragraph or a text table
    If oPar.supportsService("com.sun.star.text.Paragraph") Then
      nPars = nPars + 1
    ElseIf oPar.supportsService("com.sun.star.text.TextTable") Then
      nTables = nTables + 1
    End If
  Loop
  MsgBox CStr(nPars) & " Paragraph(s)" & CHR$(13) &_
         CStr(nTables) & " Table(s)" & CHR$(13), 0,_
         "Paragraph Types In Document"
End Sub


你可能感兴趣的:(工作,object,table,Integer,文档,Types)