Conditional formatting-reset-button with Python macro in Calc?

  • I have specific cell ranges that should always have specific conditional formatting
  • I’m going to move some of these cells around, delete their contents, cut them, etc.
  • Right now, I manually reset the ranges in Format → Conditional → Manage, deleting the single-celled ones, and reentering e.g. “A1:B1000” into one, and “C2:C1000” into another
  • Pressing a button that did this would be significantly better, as
  • Freezing/locking conditional formatting to specific cell ranges seems impossible for now
  • Python seems like the best language to use for macros
  • The Python-stuff I found is overwhelming, and speaks of installing an IDE, even though Calc seems to already have a built in editor

How do I go about doing this? =)

Yes, Python is great. A simple example:

import uno
from com.sun.star.beans import PropertyValue
from com.sun.star.sheet.ConditionOperator import EQUAL

def main():
    doc = XSCRIPTCONTEXT.getDocument()
    rango = doc.Sheets[0]['A1:A10']

    cf = rango.ConditionalFormat
    cf.clear()
    args = dict(
        Operator = EQUAL,
        Formula1 = '10',
        StyleName = 'Good',
    )
    pv = [PropertyValue(Name=n, Value=v) for n, v in args.items()]
    cf.addNew(pv)
    rango.ConditionalFormat = cf
    return

IMPORTANT: Property Formula1 always is String, StyleName should be exists.

besides learning python is no fail at all … you need not re-invent the wheel …

what about ‘clear direct formatting’?

and depending on the style to work - fingers on mouse or on keyboard - a keyboard shortcut is often faster than a button, as you save the time to select the button as target,

and - oh wonder - ‘clear direct formatting’ already has one, thus you can save all that stuff with macro, programming, testing, key or shortcut assignment, transfer to other systems …

just press ctrl-m,

and - one more wonder - for those who like buttons there already is one, its in the toolbar above the paint bucket for the background, right to the paintbrush for ‘clone formatting’, and looks like a letter ‘A’ with a red eraser,

isn’t that ‘good service’?

No. This is not good service. It is badly written, and doesn’t answer the question; “Clear Direct Formatting” removes the formatting from the selected cells. It does not reset the formatting to what it was before

sorry, didn’t check that you wanted ‘reset’ to a former - not mentioned - format … for that … macro …