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

本文介绍了一段用于统计文档中段落数量和表格数量的宏代码。该宏使用了StarOffice API来遍历文档中的每一个元素,并通过判断元素类型来累加段落和表格的数量。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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


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


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值