[Solved] Cell's background color

The Application Programming Interface and the OASIS Open Document Format

[Solved] Cell's background color

Postby ikw_chen » Mon May 30, 2011 6:29 pm

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.
Last edited by ikw_chen on Wed Jun 01, 2011 5:52 pm, edited 1 time in total.
Openoffice 3.3 on WinXP
ikw_chen
 
Posts: 17
Joined: Tue Apr 12, 2011 4:03 pm

Re: cell's background color

Postby B Marcelly » Mon May 30, 2011 8:31 pm

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
B Marcelly
Volunteer
 
Posts: 1160
Joined: Mon Oct 08, 2007 1:26 am
Location: France, Paris area

Re: Cell's background color

Postby ikw_chen » Tue May 31, 2011 6:57 pm

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
ikw_chen
 
Posts: 17
Joined: Tue Apr 12, 2011 4:03 pm

Re: Cell's background color

Postby B Marcelly » Wed Jun 01, 2011 9:11 am

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

OpenOffice.org 1.1.5 / Apache OpenOffice 4.1.1 / LibreOffice 5.0.5
MS-Windows 7 Home SP1
B Marcelly
Volunteer
 
Posts: 1160
Joined: Mon Oct 08, 2007 1:26 am
Location: France, Paris area

Re: Cell's background color

Postby ikw_chen » Wed Jun 01, 2011 5:52 pm

Hi B Marcelly,

Thanks so much :)

Regards,
Openoffice 3.3 on WinXP
ikw_chen
 
Posts: 17
Joined: Tue Apr 12, 2011 4:03 pm

Re: [Solved] Cell's background color

Postby nissim » Fri Oct 05, 2012 4:57 pm

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))
Nissim Kaufmann
Research Scientist
www.ILS.albany.edu
OpenOffice 3.5 on LinuxMint 13 Maya
nissim
 
Posts: 1
Joined: Thu Oct 04, 2012 4:39 am

Re: [Solved] Cell's background color

Postby rautamiekka » Sat Oct 22, 2016 1:31 am

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.
LibreOffice 5.2.2.2, Window$ 7 Ultimate SP1 x64
rautamiekka
 
Posts: 5
Joined: Tue Sep 28, 2010 12:54 pm
Location: Finland

Re: [Solved] Cell's background color

Postby Villeroy » Mon Oct 24, 2016 12:44 am

Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 16.04, OpenOffice 4.x & LibreOffice 5.x
User avatar
Villeroy
Volunteer
 
Posts: 24652
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany


Return to UNO API and ODF

Who is online

Users browsing this forum: No registered users and 3 guests