Libreoffice yapıştırmayla ilgili makrolar

Başlatan JKramer, 20 Nisan 2016, 11:09:53

JKramer

Merhaba,

İki tane makro lazım oldu. Birincisi formatsız yapıştırma. Normalde web sitesi ya da başka bir yerden kopyaladığımız metni Calc altında Ctrl+V ile yapıştırdığımızda formatlı yapıştırıyor. Yani yazı tipi, büyüklüğü, vb. özellikleri neyse aynen alıyor. Aşağıdaki makroyu kaydettikten sonra ben Ctrl+Q'ya atadım (Ctrl+U tek elle olmuyor :) ), bununla yapıştırırken formatsız yapıştırıyor:

https://ask.libreoffice.org/en/question/1035/paste-unformatted-text-default-option/

Alıntı YapMy favorite shortcut key for 'Paste unformatted text' is 'Ctrl+U', assigned to that macro:

sub paste_unformatted
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 ----------------------------------------------------------------------
dim args1(0) as new com.sun.star.beans.PropertyValue
args1(0).Name = "SelectedFormat"
args1(0).Value = 1

dispatcher.executeDispatch(document, ".uno:ClipboardFormatItems", "", 0, args1())

end sub


You may create this macro as follows:

(1) Record macro

Ctrl+Shift+V > U > Enter

Stop recording

(2) [New window: LibreOffice Basic Macros]

Type 'Macro name' (e.g.): 'paste_unformatted' > Save

(3) Tools > Customize > Keyboard > Functions > Category > LibreOffice Macros > user > Standard > Module1

Function > 'paste_unformatted'

Shortcut keys > Ctrl+U > Modify > OK

İkincisi, bir web sitesinin adresini yapıştırırken hyperlink (Ctrl ile tıklandığında tarayıcıda sayfayı açıyor) olarak yapıştırma. Normalde bunu yapmak için Ctrl+K, Yapıştır, OK demek lazım. Aşağıdaki makroyu da Ctrl+G'ye atadım, basınca linkli olarak yapıştırıyor:
sub PasteHyperlink
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 ----------------------------------------------------------------------
dim args1(4) as new com.sun.star.beans.PropertyValue
dim sText As string
sText= (getClipboardText)
args1(0).Name = "Hyperlink.Text"
args1(0).Value = sText
args1(1).Name = "Hyperlink.URL"
args1(1).Value = sText
args1(2).Name = "Hyperlink.Target"
args1(2).Value = ""
args1(3).Name = "Hyperlink.Name"
args1(3).Value = ""
args1(4).Name = "Hyperlink.Type"
args1(4).Value = 1

dispatcher.executeDispatch(document, ".uno:SetHyperlink", "", 0, args1())


end sub

' get the text from the clipboard and removes formatting
Function getClipboardText () AS String
dim oClip as object ,oConverter as object
dim oClipContents as object ,oTypes as object
dim i%
oClip = createUnoService("com.sun.star.datatransfer.clipboard.SystemClipboard")
oConverter = createUnoService("com.sun.star.script.Converter")
On Error Resume Next
oClipContents = oClip.getContents
oTypes = oClipContents.getTransferDataFlavors
For i=LBound(oTypes) To UBound(oTypes)
  If oTypes(i).MimeType = "text/plain;charset=utf-16" Then
    Exit For
  End If
Next
If (i >= 0) Then
  On Error Resume Next
  getClipboardText = oConverter.convertToSimpleType _
        	     (oClipContents.getTransferData(oTypes(i)), com.sun.star.uno.TypeClass.STRING)
End If
End Function