1

In a python Calc macro, I want to be able to hide text in a cell.

One way to do that is to get the background color of a cell and then set the text to that same color:

bg_color = oCell.CellBackColor
oCell.String = "Cell BG Color: " + hex(bg_color)
oCell.CharColor = bg_color

However the above code results in cell text "Cell BG Color: -1", not the actual color value for the cell background. I'm assuming '-1' causes the cell to be rendered with a default color.

SO - unless I set that color myself, the call "bg_color = oCell.CellBackColor" returns -1 instead of an RGB color integer. The following works:

bg_color = oCell.CellBackColor
oCell.CellBackColor = RGB(220,210,200)
oCell.String = "Cell BG Color: " + hex(bg_color)
oCell.CharColor = bg_color

That code results in cell text "Cell BG Color: 0xc8d2dc", the same color as the cell background making the text invisible to the eye, which I have checked by copying the cell and doing a "Paste-Special > Text" into another cell. Note the ability to copy is not a security issue here, I'm just making a spreadsheet of foreign language drills.

To avoid having to explicitly set cell background colors, I thought it would work if I could set the alpha channel on the text color, BUT - I can't find any reference on how to do that for cell text. I tried adding a 4th parameter to RGB() but that doesn't seem to work.

Is it possible, and if so how? Is there an alpha property separate from CharColor?

I don't want to go through the mess of changing the "hidden" attribute in protection settings because that seems to not take effect unless you protect the entire sheet, and that requires password entry - just too messy.

Pᴇʜ
  • 56,719
  • 10
  • 49
  • 73
CJH
  • 163
  • 1
  • 12

0 Answers0