Es reicht mir nicht immer aus, die Hintergrundfarbe von Zellen zu ändern.
Daher habe ich ein Makro zur Einfügung einer Grafik in eine Zelle für meinen Zweck so angepasst, dass dies für mehrere selektierte Zellen gleichzeitig geht.
Code: Alles auswählen
Sub BildEinfuegen
Dim oDoc as Object
Dim oSheet as Object
Dim oCell as Object
Dim Page as Object
Dim GrafikName as String
osheet = ThisComponent.CurrentController.ActiveSheet
osheet = thisComponent.sheets.getByName(osheet.name)
oDoc = thisComponent
oSel = oDoc.getCurrentSelection()
oSel.CellBackColor = RGB ( 45,87,166)
oRange = oSheet.getCellRangeByPosition(1,0,1,25)
oDoc.currentController.select( oRange )
oCellRange = oDoc.getCurrentSelection()
iErsteZeile = oCellRange.rangeAddress.startRow
iLetzteZeile = oCellRange.rangeAddress.EndRow
For i = iErsteZeile to iLetzteZeile
oCell2 = osheet.getCellByPosition(1,i)
If oCell2.CellBackColor = RGB ( 45,87,166) Then
Page = osheet.drawPage
NewGrafik = oDoc.createInstance("com.sun.star.drawing.GraphicObjectShape")
oCell = osheet.getCellRangeByName("A1")
GrafikName = ConvertToURL(oCell.String)
if not FileExists(GrafikName) then
msgbox "Die Grafik ist nicht vorhanden!"
exit sub
end if
NewGrafik.GraphicURL=GrafikName
NewGrafik.name = GrafikName
page.add(NewGrafik)
NewGrafik.Anchor = oCell2
Dim Size As New com.sun.star.awt.Size
oBildGroesse =NewGrafik.GraphicObjectFillBitmap.GetSize
hoehe = oBildGroesse.height ' in Pixeln
breite = oBildGroesse.width 'in Pixeln
dim oGrafikGroesse as new com.sun.star.awt.Size
oGrafikGroesse.height = hoehe * 16 'Grösse festlegen
oGrafikGroesse.width = breite * 8.6
NewGrafik.setSize(oGrafikGroesse)
NewGrafik.setPosition(NewGrafik.anchor.Position)
oCell2.CellBackColor = -1
EndIf
Next i
oCell3 = osheet.getCellByPosition(1,1)
oDoc.currentController.select(oCell3 )
End Sub
Die Suche in den Foren blieb leider erfolg- und eigene Versuche ergebnislos.
Die Beispieldatei habe ich auf das Wesentliche für meine Fragestellung reduziert. Danke im Voraus,
Ralf