如何在 LibreOffice 中使用宏和 Visual Basic 突出显示文本
How to highlight text using macros and visual basic in LibreOffice
我必须编写一个突出显示特定数字的宏(将背景颜色设置为黄色)。
我已经编写了一个使用对象 Cursor 查找这些数字的宏,但我不知道如何更改背景颜色。
Dim Cursor As Object
Dim Proceed As Boolean
Cursor = ThisComponent.Text.createTextCursor()
Cursor.gotoStart(False)
Do
Cursor.gotoEndOfWord(True)
'some If statements that check if the number is correct
'Cursor.CharEmphasis = com.sun.star.text.FontEmphasis.DOT_BELOW
Proceed = Cursor.gotoNextWord(False)
Loop While Proceed
我发现了一个强调文字的功能,在文字下方加点。有没有类似的突出文本的东西?
以下代码将在从 col1 到 col2 和 row1 到 row2 的单元格范围内,条目小于 MY_MIN 或大于 MY_MAX 的任何单元格放置黄色背景。
For I = col1 To col2
For J = row1 to row2
Cell = Sheet.getCellByPosition(I,J)
If Cell.Type <> com.sun.star.table.CellContentType.EMPTY Then
If Cell.Value < MY_MIN Or Cell.Value > MY_MAX Then
Cell.CellBackColor = RGB(200,200,0)
End If
End If
Next J
Next I
希望这能解决您的问题。
您正在寻找 CharBackColor:
oCursor.CharBackColor = RGB(255,255,0)
我必须编写一个突出显示特定数字的宏(将背景颜色设置为黄色)。
我已经编写了一个使用对象 Cursor 查找这些数字的宏,但我不知道如何更改背景颜色。
Dim Cursor As Object
Dim Proceed As Boolean
Cursor = ThisComponent.Text.createTextCursor()
Cursor.gotoStart(False)
Do
Cursor.gotoEndOfWord(True)
'some If statements that check if the number is correct
'Cursor.CharEmphasis = com.sun.star.text.FontEmphasis.DOT_BELOW
Proceed = Cursor.gotoNextWord(False)
Loop While Proceed
我发现了一个强调文字的功能,在文字下方加点。有没有类似的突出文本的东西?
以下代码将在从 col1 到 col2 和 row1 到 row2 的单元格范围内,条目小于 MY_MIN 或大于 MY_MAX 的任何单元格放置黄色背景。
For I = col1 To col2
For J = row1 to row2
Cell = Sheet.getCellByPosition(I,J)
If Cell.Type <> com.sun.star.table.CellContentType.EMPTY Then
If Cell.Value < MY_MIN Or Cell.Value > MY_MAX Then
Cell.CellBackColor = RGB(200,200,0)
End If
End If
Next J
Next I
希望这能解决您的问题。
您正在寻找 CharBackColor:
oCursor.CharBackColor = RGB(255,255,0)