工作期间需要统计出当前文档所有段落和表格,摘出其中一段宏:
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
统计文档段落与表格
本文介绍了一个用于统计文档中段落数量和表格数量的宏。通过使用 com.sun.star 容器接口,宏能够遍历文档的所有元素,并区分它们是普通段落还是表格。
1万+

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



