[Solved] Cell's background color

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
ikw_chen
Posts: 17
Joined: Tue Apr 12, 2011 4:03 pm

[Solved] Cell's background color

Post 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.
Last edited by ikw_chen on Wed Jun 01, 2011 5:52 pm, edited 1 time in total.
Openoffice 3.3 on WinXP
B Marcelly
Volunteer
Posts: 1160
Joined: Mon Oct 08, 2007 1:26 am
Location: France, Paris area

Re: cell's background color

Post 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...
Bernard

OpenOffice.org 1.1.5 / Apache OpenOffice 4.1.1 / LibreOffice 5.0.5
MS-Windows 7 Home SP1
ikw_chen
Posts: 17
Joined: Tue Apr 12, 2011 4:03 pm

Re: Cell's background color

Post 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!.
Openoffice 3.3 on WinXP
B Marcelly
Volunteer
Posts: 1160
Joined: Mon Oct 08, 2007 1:26 am
Location: France, Paris area

Re: Cell's background color

Post 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/r ... lBackColor
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).
Bernard

OpenOffice.org 1.1.5 / Apache OpenOffice 4.1.1 / LibreOffice 5.0.5
MS-Windows 7 Home SP1
ikw_chen
Posts: 17
Joined: Tue Apr 12, 2011 4:03 pm

Re: Cell's background color

Post by ikw_chen »

Hi B Marcelly,

Thanks so much :)

Regards,
Openoffice 3.3 on WinXP
nissim
Posts: 1
Joined: Thu Oct 04, 2012 4:39 am

Re: [Solved] Cell's background color

Post 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))
Nissim Kaufmann
Research Scientist
www.ILS.albany.edu
OpenOffice 3.5 on LinuxMint 13 Maya
rautamiekka
Posts: 5
Joined: Tue Sep 28, 2010 12:54 pm
Location: Finland

Re: [Solved] Cell's background color

Post 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

Code: Select all

-1
regardless of the bg color. Tested LibreOffice 5.2.2.2.
LibreOffice 5.2.2.2, Window$ 7 Ultimate SP1 x64
User avatar
Villeroy
Volunteer
Posts: 31269
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: [Solved] Cell's background color

Post by Villeroy »

Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Post Reply