Page 1 of 1

[Solved] Change backcolor of a text in Calc

Posted: Fri Jan 19, 2024 11:18 am
by VBandOoffice
Happy New Year to everyone!

I found a strange thing by trying to protect a text in calc.
First step to final goal is to mark this text, but why it is not possible to change the back color from the beginning?
(If I start from beginning, there is no back color at all)

Code: Select all

Sub Get_FilePath
rem ----------------------------------------------------------------------
rem define variables
dim document   as object

dim oDoc as Object
dim oSheet as Object
dim oCell as Object
Dim oCursor As Object
Dim oSelection As Object
dim sDocumentPath as String

rem ----------------------------------------------------------------------
rem get access to the document
document   = ThisComponent.CurrentController.Frame
sDocumentPath = environ("HOMEDRIVE") + environ("HOMEPATH")

oDoc = thisComponent
oSheet = oDoc.currentcontroller.activesheet 

rem ----------------------------------------------------------------------

oCell = oSheet.getCellrangeByName("B20")
oCell.string=" Protected Text"

oCursor= oCell.CreateTextCursor()
oCursor.gotoStart(False)
'with start from beginning or goRight=0 no BackColor is visible
oCursor.goRight(1,False)
oCursor.gotoEnd(True)

REM - it has worked once to get BackColor to the beginning,
'but it was a small white gap after first charakter:
'oCursor.gotoStart(True) 

'oCursor.CharWeight = 150  'Fett
'oCursor.CharPosture = 2   'Kursiv
oCursor.CharBackColor = RGB(192, 192, 192)
oCursor.CharBackTransparent = 0
xray oCursor

End Sub
Thanks for your time
-VBandOpenOffice-

Re: Change backcolor of a text in calc

Posted: Fri Jan 19, 2024 2:28 pm
by JeJe
I notice that charbackcolor isn't a property of the cell or the cell text and isn't available as an option in the character properties dialog - though the text color is. The property looks to be only available via a macro with cursor.

This link says its not working in calc:

https://ask.libreoffice.org/t/highlight ... lc/26534/5


Further searching may give you an explanation but CellBackColor looks to be the only option.

Re: Change backcolor of a text in calc

Posted: Fri Jan 19, 2024 7:05 pm
by JeJe
Investigating a little further. In OO the cursor doesn't even have that property.

CharBackColor is not supported in either OO or LO and its pointless applying it - as when you save and reopen the document the CharBackColor change made with your macro is lost. It isn't saved to the file (to content.xml).

Re: Change backcolor of a text in calc

Posted: Mon Jan 22, 2024 8:02 am
by VBandOoffice
Hello JeJe,
thanks for your work - You are right, BackColor is not saved! (I didn't checked this before)
Ok, this is not the right way. I'll make a new topic, if someone knows, how "Field Commands" do this.

Best regards,
-VBandOpenOffice-