What is an expression? Is this a formula? Dear Lupp, sorry I would be more helped if you give me one solution (the best :-)) to try first, not also 2 or 3 alternatives. And this one solution I need to understand. And just get an example maybe, an ods for instance where this is done. I feel treated unfair by you. To understand what I want you can ask me and I will answer. And I appreciate if you do the same. You explain just to complicated and too much different things from my point of view.
I also have the impression that I have already given clear answers and you have not read them.
And you advice me some things I have already done and written to you also, like been trying with your example file. Honestly I am frustrated now with your reactions.
Two work-arounds I have found. (I presently run LibreOffice 5.0.4.2 (x64) on Windows 10 64-bit. I have not tested other versions or platforms, so your results may vary.)
The first method won’t give you the colour code, but it should let you set the background colour to the one you want without disturbing anything else, assuming it is already used in the document. Select the cell you want to colour. Open the Background dialog. There are several available palettes. Click the down arrow and select the “Document colors” palette. This palette appears to show only the colours in use in the current document (may include colours no longer in use). From this (hopefully) short list, it is relatively easy to match the colour you want.
The second method depends on having specific additional software installed. Other programs may work similarly, but the only one I have found so far is Snagit (presently using Ver 11). In Snagit, pick an editing option that lets you choose the fill colour. Snagit lets you take the eyedropper cursor outside the program window. Hover over the cell whose background colour you wish to copy, and the Tooltip will give the RGB values. From there you can use the Custom Color option in the LO Background dialog to duplicate it. As for other programs, I know Windows Paint and The Gimp will not work. Snagit works on Windows and Mac only, but other screen capture programs may have a similar capability.
(Sorry I could not post screen shots - not enough karma.)
Did you consider that the palettes and the color names were often changed? The actual colors (RGB) assigned to any names are subject to changes by the developers and by the user as well. The color name originally displayed when a color value was set is not stored. And surely there aren’t names for everyone of the 2^24 colors of the currently used color space.
Hello @MichaelFontaine, and @Hopeful-LO-user
In addition to the macro given by @Lupp, which returns the RGB values of the Cell Background Color as an Array, the following macro returns the color’s RGB values as a single Long Integer, and the next following macro returns the color’s HEX values as a String.
Just call in your Calc cell: = getCellBackColorRGB(“A1”)
or =getCellBackColorHEX( “A1” )
Function getCellBackColorRGB( strCellAddress$ ) As Long
REM <strCellAddress>: pass a Cell address in the current Sheet, such as "A1" or "$A$1".
REM Returns a Long Integer representing the RGB values of the Background Color of the specified Cell.
Dim oSheet As Object : oSheet = ThisComponent.CurrentController.ActiveSheet
Dim oCell As Object : oCell = oSheet.getCellRangeByName( strCellAddress )
getCellBackColorRGB = oCell.CellBackColor
End Function
Function getCellBackColorHEX( strCellAddress$ ) As String
REM <strCellAddress>: pass a Cell address in the current Sheet, such as "A1" or "$A$1".
REM Returns a String representing the HEX values of the Background Color of the specified Cell.
Dim oSheet As Object : oSheet = ThisComponent.CurrentController.ActiveSheet
Dim oCell As Object : oCell = oSheet.getCellRangeByName( strCellAddress )
getCellBackColorHEX = RGBtoHEX( oCell.CellBackColor )
End Function
Function RGBToHex( lRGB As Long ) As String
RGBToHex = ByteToHex( Red( lRGB ) ) & ByteToHex( Green( lRGB ) ) & ByteToHex( Blue( lRGB ) )
End Function
Function ByteToHex( iByte As Integer ) As String
Dim strHex As String : strHex = Hex( iByte )
If Len( strHex ) = 1 Then strHex = "0" & strHex
ByteToHex = strHex
End Function
HTH, lib