如何編寫巨集來使選定的單字成為強調標記?

如何編寫巨集來使選定的單字成為強調標記?

如何為 OpenOffice writer 編寫一個宏,使我用滑鼠選擇的單字/字元在單字/字元上帶有強調標記(如點)?

我嘗試錄製宏,但失敗了。

我希望這裡有人可以幫助我


我正在嘗試為 OpenOffice Writer 和 LibreOffice Writer 編寫巨集。該巨集將在 Writer 中新增一個工具列,類似於中文版 MS Word 中的中文標點符號工具列。工具列的按鈕是中文標點符號。其中一個按鈕將是中國簡體中文中使用的強調標記。強調標記是當文字方向為橫向時在強調的漢字下方的一個點,當文字方向為縱向時在強調的漢字右側的一個點。

我不知道OpenOffice Basic或其他用於編寫電腦程式的語言,但我知道Writer的巨集記錄器可以記錄一些程式碼,可以用來編寫我需要的巨集。我不斷在谷歌上搜索以找到更多資訊並學習編寫巨集。對於大多數標點符號,程式碼都很簡單。

例如,要插入停止標記,代碼為:

rem U+3002
sub cp01
dim document   as object
dim dispatcher as object
document   = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
dim args1(0) as new com.sun.star.beans.PropertyValue
args1(0).Name = "Text"
args1(0).Value = "。"
dispatcher.executeDispatch(document, ".uno:InsertText", "", 0, args1())
end sub

但 LibreOffice 3.4 的巨集記錄器未能為強調標記記錄可用的巨集。實際上,當我在Writer的字元對話框的字體效果中將強調標記從“(無)”更改為“點”時,Writer就意外關閉了。我被迫下載並安裝 OpenOffice.org 3.3 和 3.4。

OpenOffice.org 3.3 的巨集記錄器也無法記錄,但 3.4 的巨集記錄器可以記錄。宏是:

sub Test20120206_1
rem --------------------------------------------
rem define variables
dim document   as object
dim dispatcher as object
rem ------------------------------------
rem get access to the document
document   = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
rem -------------------------------
dispatcher.executeDispatch(document, ".uno:EmphasisMark", "", 0, Array())
end sub

這個宏不起作用。

答案1

我找到了網頁: http://user.services.openoffice.org/en/forum/viewtopic.php?f=45&t=21813

FJCC 的一個巨集讓我非常高興,因為它很短,並且關於如何對選定的角色應用效果,這可能是我所需要的。

Doc = ThisComponent
Selections = Doc.CurrentSelection
FirstSelection = Selections.getByIndex(0)
TextString = FirstSelection.String
UCaseStr = UCase(TextString)
FirstSelection.String = UCaseStr

然後我將這段程式碼與 MS Word、日文和 Pitonyak A. 中的巨集重新組合,找到了一個可行的程式碼:

sub EmphasisMark
Doc = ThisComponent
Selections = Doc.CurrentSelection
FirstSelection = Selections.getByIndex(0)
  If  FirstSelection.CharEmphasis = com.sun.star.text.FontEmphasis.NONE Then
      FirstSelection.CharEmphasis = com.sun.star.text.FontEmphasis.DOT_BELOW
  Else
      FirstSelection.CharEmphasis = com.sun.star.text.FontEmphasis.NONE
  End If
end sub

這就是我需要的。最後...

相關內容