工作期间需要统计出当前文档所有段落和表格,摘出其中一段宏:
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
本文介绍了一段用于统计文档中段落数量和表格数量的宏代码。该宏使用了StarOffice API来遍历文档中的每一个元素,并通过判断元素类型来累加段落和表格的数量。
1万+

被折叠的 条评论
为什么被折叠?



