当前位置: 代码迷 >> Office >> openoffice -查寻文本并设置文本字体的宏
  详细解决方案

openoffice -查寻文本并设置文本字体的宏

热度:6831   发布时间:2013-02-26 00:00:00.0
openoffice --查找文本并设置文本字体的宏
Sub Main
    Dim oDocument As Object
    Dim oSearch As Object, oResult As Object
    Dim oFound As Object, oFoundCursor As Object
    Dim n As Long
    oDocument = ThisComponent
    oSearch = oDocument.createSearchDescriptor
    'oSearch.SearchString = "the[a-z]"
    oSearch.SearchString = "x"
    oSearch.SearchRegularExpression = TRUE
    oResult = oDocument.findAll(oSearch)
    For n = 0 To oResult.count - 1
    oFound = oResult(n)
    oFoundCursor = oFound.Text.createTextCursorByRange(oFound)
    oFoundCursor.CharWeight = com.sun.star.awt.FontWeight.BOLD
    Next n
    'oSearch.SearchString = "all[a-z]"
    oSearch.searchString = "y"
    oFound = oDocument.findFirst(oSearch)
    While NOT IsNull(oFound)
    oFoundCursor = oFound.Text.createTextCursorByRange(oFound)
    oFoundCursor.CharPosture = com.sun.star.awt.FontSlant.ITALIC
    oFound = oDocument.findNext(oFound, oSearch)
    Wend
End Sub