[Solved] Can't update calc cell background color

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
tabsquare
Posts: 5
Joined: Mon Oct 27, 2014 2:07 am

[Solved] Can't update calc cell background color

Post by tabsquare »

Hi all, I am trying to update the cell background of the selected cell in calc.

Code: Select all

sub changecolor()
	dim oCell
	
	oCell = ThisComponent.getCurrentSelection() 
        oCell.CellBackColor = RGB(0,204,0)

End Sub
however nothing happens when I launch the macro. If I add the code

Code: Select all

oCell.SetString("oops")
It will work. But I actually don't want the text content to be modified. Any idea? thx
Last edited by Hagar Delest on Thu Jan 25, 2018 10:07 pm, edited 1 time in total.
Reason: tagged [Solved].
OpenOffice 4.0.1 on Ubuntu 14.04 LTS
FJCC
Moderator
Posts: 9248
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: Can't update calc cell background color

Post by FJCC »

Your original code, without the setString(), works for me on both Windows 10 and Linux Mint. I can't think of any setting that would change this but I will give it some more thought.
OpenOffice 4.1 on Windows 10 and Linux Mint
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
tabsquare
Posts: 5
Joined: Mon Oct 27, 2014 2:07 am

Re: Can't update calc cell background color

Post by tabsquare »

Don't know, I tried many and many times and seems an odd behavior. I'm win 10 with OO 4.1.2. Thx
OpenOffice 4.0.1 on Ubuntu 14.04 LTS
tabsquare
Posts: 5
Joined: Mon Oct 27, 2014 2:07 am

Re: Can't update calc cell background color

Post by tabsquare »

Ok I know why it does this. In fact it works in blank cells. It isn't working on cells I previously created a lot of time ago so I didn't realize. A sample cell contains this kind of code

Code: Select all

=G756+"744:00:00"+T(STYLE(IF(NOW()>G756+"744:00:00";"red";"normal")) )
it is obviously refreshing the color to red even if the macro sets it to green.
I am quite surely supposed to change this code at macro runtime. Working on this. Thanks for taking the time to take a look into this. My fault.
OpenOffice 4.0.1 on Ubuntu 14.04 LTS
FJCC
Moderator
Posts: 9248
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: Can't update calc cell background color

Post by FJCC »

Thanks for coming back to explain what the problem was. Others may find that useful.
OpenOffice 4.1 on Windows 10 and Linux Mint
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
Post Reply