[Solved] Change backcolor of a text in Calc

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
VBandOoffice
Posts: 33
Joined: Tue Jul 31, 2018 10:11 am

[Solved] Change backcolor of a text in Calc

Post 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-
Last edited by VBandOoffice on Mon Jan 22, 2024 8:04 am, edited 2 times in total.
LibreOffice 7.5, Windows 10, VB.net 2019, C#
JeJe
Volunteer
Posts: 2785
Joined: Wed Mar 09, 2016 2:40 pm

Re: Change backcolor of a text in calc

Post 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.
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
JeJe
Volunteer
Posts: 2785
Joined: Wed Mar 09, 2016 2:40 pm

Re: Change backcolor of a text in calc

Post 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).
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
VBandOoffice
Posts: 33
Joined: Tue Jul 31, 2018 10:11 am

Re: Change backcolor of a text in calc

Post 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-
LibreOffice 7.5, Windows 10, VB.net 2019, C#
Post Reply