Conditional formatting and clearContents

Using the following lines in my Calc macro:

oRange = ThisComponent.Sheets.getByName("MySheet").getCellRangeByName("I21:AC47")
oRange.clearContents(1)

It also clears the Conditional formatting, why ?

clearContents(1) should only remove a VALUE right ?

Yes, of course - you are right: clearContents(1) remove a VALUE only. Your macro did it in my test sheet (conditional formats wasn’t changed). What conditions and what styles you use when macro not work properly?

Well to be honest I didn’t try it in a new sheet…(Iwill do that) It used to work but after a certain update (I do know when unfortunately, because I didn’t notice the loss of the conditional format). I use a formula IF(I$60= “c”) and apply a defined ‘My_Style’ some colour stuff.

Sorry, I do not quite understand the meaning of the condition. "If the value in line 60 is exactly equal to “C” … So what? Then?.. Else?.. Maybe you didn’t mean IF(), but just a comparison?

Eh, If I$60 contains a “c” Then apply style ‘My_Style’ is what I’m doing for a row so I have a visual cue about the state (contained in the I$60 cell) of the sheet, if you understand what i’m saying…

Yes, I think I understand what you are saying :slight_smile: I meant that the conditional format in this case can be written without using the function IF().

Your macro works correctly. In the range “I21:AC47” removed only numbers. Strings, formulas and conditional formats are in place.

ClearCondFormat.ods - your macro and my variant of conditional formatting