Page 1 of 1

[Solved] Cell's background color

PostPosted: Mon May 30, 2011 6:29 pm
by ikw_chen
Hi All,

I try to get the cell's background color with below code, but it doesn't work

Code: Select all   Expand viewCollapse view
xCellProps = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, xCell);
            
System.out.println(xCellProps.getPropertyValue("BackColor").toString());

and it's throw exception:
Code: Select all   Expand viewCollapse view
com.sun.star.beans.UnknownPropertyException:
   at com.sun.star.lib.uno.environments.remote.Job.remoteUnoRequestRaisedException(Job.java:177)
   at com.sun.star.lib.uno.environments.remote.Job.execute(Job.java:143)

Please advice!

Thanks.

Re: cell's background color

PostPosted: Mon May 30, 2011 8:31 pm
by B Marcelly
Hi,
Where is your cell ? in a sheet of a Calc document ? or in a table in a Writer document ? or elsewhere ?

For Calc documents, the background color is property CellBackColor.
For Writer documents, the background color is indeed property BackColor.
Read Developer's Guide...

Re: Cell's background color

PostPosted: Tue May 31, 2011 6:57 pm
by ikw_chen
Hi B Marcelly,

It's cell in sheet of Calc document.

after get the CellBackColor property, it's return value like this: 16776960

Is there any method to convert the above number to string like: Yellow?

Thanks for advice!.

Re: Cell's background color

PostPosted: Wed Jun 01, 2011 9:11 am
by B Marcelly
Use the IDL documentation of the SDK.
With the on-line IDL:
Search in the index the Property CellBackColor for service CellProperties :arrow: http://api.openoffice.org/docs/common/ref/com/sun/star/table/CellProperties.html#CellBackColor
In the description of the property, link to ::com::sun::star::util::Color CellBackColor
You can get the Red Green Blue components of the color.

A color has no name by itself. The OOo palette only gives names to 100 colors out of (2 power 24) colors and may differ between versions (and in LibreOffice).

Re: Cell's background color

PostPosted: Wed Jun 01, 2011 5:52 pm
by ikw_chen
Hi B Marcelly,

Thanks so much :)

Regards,

Re: [Solved] Cell's background color

PostPosted: Fri Oct 05, 2012 4:57 pm
by nissim
In LibreOffice Calc:

Go to Tools>Macros>Organize Macros>LibreOffice Basic>
My Macros>Standard>Module1

Select "Main" and click "Edit."
It will contain the empty 3-line template "REM ***BASIC****\\ Sub Main\\ End Sub".
Add this after the template:

Code: Select all   Expand viewCollapse view
Function bgcolor(c,r)
  Dim oDoc  As Object   ' define variables
  Dim oSheet As Object
  Dim oCell As Object
  oDoc  = ThisComponent
  oSheet= oDoc.getSheets().getByIndex(0)
  oCell = oSheet.getCellByPosition(c-1,r-1)
  bgcolor = oCell.CellBackColor
End Function

Examples:
bgcolor(3,1)
bgcolor(3, CELL("Row",A1))

Re: [Solved] Cell's background color

PostPosted: Sat Oct 22, 2016 1:31 am
by rautamiekka
nissim wrote:In LibreOffice Calc:

Go to Tools>Macros>Organize Macros>LibreOffice Basic>
My Macros>Standard>Module1

Select "Main" and click "Edit."
It will contain the empty 3-line template "REM ***BASIC****\\ Sub Main\\ End Sub".
Add this after the template:

Code: Select all   Expand viewCollapse view
Function bgcolor(c,r)
  Dim oDoc  As Object   ' define variables
  Dim oSheet As Object
  Dim oCell As Object
  oDoc  = ThisComponent
  oSheet= oDoc.getSheets().getByIndex(0)
  oCell = oSheet.getCellByPosition(c-1,r-1)
  bgcolor = oCell.CellBackColor
End Function

Examples:
bgcolor(3,1)
bgcolor(3, CELL("Row",A1))

That code always returns
Code: Select all   Expand viewCollapse view
-1
regardless of the bg color. Tested LibreOffice 5.2.2.2.

Re: [Solved] Cell's background color

PostPosted: Mon Oct 24, 2016 12:44 am
by Villeroy