[Solved] Can't update calc cell background color

Creating a macro - Writing a Script - Using the API

[Solved] Can't update calc cell background color

Postby tabsquare » Thu Jan 25, 2018 6:40 pm

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

Code: Select all   Expand viewCollapse view
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   Expand viewCollapse view
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
tabsquare
 
Posts: 5
Joined: Mon Oct 27, 2014 2:07 am

Re: Can't update calc cell background color

Postby FJCC » Thu Jan 25, 2018 7:22 pm

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.
Windows 10 and Linux Mint, since 2017
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
FJCC
Moderator
 
Posts: 7307
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: Can't update calc cell background color

Postby tabsquare » Thu Jan 25, 2018 7:30 pm

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

Postby tabsquare » Thu Jan 25, 2018 8:50 pm

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   Expand viewCollapse view
=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
tabsquare
 
Posts: 5
Joined: Mon Oct 27, 2014 2:07 am

Re: Can't update calc cell background color

Postby FJCC » Thu Jan 25, 2018 9:01 pm

Thanks for coming back to explain what the problem was. Others may find that useful.
Windows 10 and Linux Mint, since 2017
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
FJCC
Moderator
 
Posts: 7307
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA


Return to Macros and UNO API

Who is online

Users browsing this forum: No registered users and 5 guests