Page 1 of 1
[Solved] Cell's background color
Posted: 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
xCellProps = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, xCell);
System.out.println(xCellProps.getPropertyValue("BackColor").toString());
and it's throw exception:
Code: Select all
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
Posted: 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
Posted: 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
Posted: 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
http://api.openoffice.org/docs/common/r ... lBackColor
In the description of the property, link to
::com::sun::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
Posted: Wed Jun 01, 2011 5:52 pm
by ikw_chen
Hi B Marcelly,
Thanks so much
Regards,
Re: [Solved] Cell's background color
Posted: 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
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
Posted: 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
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
regardless of the bg color. Tested LibreOffice 5.2.2.2.
Re: [Solved] Cell's background color
Posted: Mon Oct 24, 2016 12:44 am
by Villeroy