Seite 1 von 1

Re: Zwischenablage in neuen Komentar einfügen

Verfasst: Sa, 20.11.2010 18:34
von Axel Richter
Hallo samy,

eine Annotation (Kommentar) per Makro einfügen, geht so:

Code: Alles auswählen

 
 sheet = ThisComponent.Sheets(0)
 cell = sheet.getCellByPosition(2,4)
 sheet.Annotations.InsertNew(cell.CellAddress, "Das ist der Kommentar")
Mit dem Code wird ein Kommentar im ersten Tabellenblatt an Zelle C5 eingefügt.
Die Größe passt sich dem Text automatisch an.

Das mit der Zwischenablage solltest Du bitte noch Mal genauer erklären. Also, was Du wirklich erreichen willst. Der Umweg über die Zwischenablage ist nämlich meist nicht nötig. Also, woher sollen die Texte für die Kommentare wirklich kommen?

viele Grüße

Axel

Re: Zwischenablage in neuen Komentar einfügen

Verfasst: Sa, 20.11.2010 19:14
von DPunch
Aloha

Mit folgendem Makro fügst Du die Zwischenablage als Kommentar mit der gewünschten Höhe/Breite an die erste selektierte Zelle an:

Code: Alles auswählen

Sub CreateAnnotationFromClipboard
	nBreite = 5000 'Gewüscnhte Breite
	nHoehe = 3000 'Gewünschte Höhe

	iPlainLoc = -1
	oClip = createUnoService("com.sun.star.datatransfer.clipboard.SystemClipboard")
	oConverter = createUnoService("com.sun.star.script.Converter")
	oClipContents = oClip.getContents
	oTypes = oClipContents.getTransferDataFlavors
	For i=LBound(oTypes) To UBound(oTypes)			
	    If oTypes(i).MimeType = "text/plain;charset=utf-16" Then
		    iPlainLoc = i
		    Exit For
		End If
	Next
	If (iPlainLoc >= 0) Then
    	convertedString = oConverter.convertToSimpleType _
    			(oClipContents.getTransferData(oTypes(iPlainLoc)), com.sun.star.uno.TypeClass.STRING)
	End If
	If Len(convertedString) = 0 Then Exit Sub
	oDoc = thisComponent
	oSheet = oDoc.CurrentController.ActiveSheet
	oSelectedCellRange = oDoc.CurrentSelection(0)
	If NOT oSelectedCellRange.supportsService("com.sun.star.sheet.SheetCellRange") Then Exit Sub
	oDoc.lockControllers
	oCellRangeAddress = oSelectedCellRange.RangeAddress
	Dim oAddress as new com.sun.star.table.CellAddress
	oAddress.Row = oCellRangeAddress.StartRow
	oAddress.Column = oCellRangeAddress.StartColumn
	oAddress.Sheet = oCellRangeAddress.Sheet
	oSheet.Annotations.insertNew(oAddress,convertedString)
	oCell = oSheet.getCellByPosition(oAddress.Column,oAddress.Row)
	oSize = oCell.Annotation.AnnotationShape.Size
	oSize.Width = nBreite
	oSize.Height = nHoehe
	oCell.Annotation.AnnotationShape.Size = oSize
	Do While oDoc.hasControllersLocked
		oDoc.unlockControllers
	Loop
End Sub