How do I rotate the text in a cell using pyuno?

I use pyuno to create a table in Writer. I would like to rotate the text in one cell. I cannot get this to work.

I first get a cell from the table using getCellByName(). This method returns a com.sun.star.table.XCell.

When I print this object, I get:

(com.sun.star.table.XCell)0x559c48583568{implementationName=SwXCell, supportedServices= 
{com.sun.star.text.CellProperties}, 
supportedInterfaces={com.sun.star.table.XCell,
com.sun.star.lang.XServiceInfo,
com.sun.star.beans.XPropertySet,
com.sun.star.container.XEnumerationAccess,
com.sun.star.lang.XTypeProvider,
com.sun.star.uno.XWeak,com.sun.star.text.XText,
com.sun.star.text.XTextRangeCompare,
com.sun.star.text.XRelativeTextContentInsert,
com.sun.star.text.XRelativeTextContentRemove,
com.sun.star.lang.XUnoTunnel,
com.sun.star.beans.XPropertySet,
com.sun.star.text.XTextPortionAppend,
com.sun.star.text.XParagraphAppend,
com.sun.star.text.XTextContentAppend,
com.sun.star.text.XTextConvert,
com.sun.star.text.XTextAppend,
com.sun.star.text.XTextAppendAndConvert}}

So, this object supports the service com.sun.star.text.CellProperties. However, I believe, in order to rotate the text I should change the Orientation or RotateAngle properties, which are both in the interface com.sun.star.table.CellProperties, and not in com.sun.star.text.CellProperties. If I try to set the Orientation of a cell that I got using getCellByName(), I get an AttributeError, indicating that the attribute does not exist.

Looking at the class tree, I would expect that an object that is returned from getCellByName() should return an object that also implements com.sun.star.table.CellProperties.

How can I access the attributes in com.sun.star.table.CellProperties, and especially Orientation and RotateAngle?

I have found the answer by looking at the source code.

Apparently the cell has a property “WritingMode” Setting this to 3 (TB_LR) (using cell.setPropertyValue(“WritingMode”, 3)) produces the result I was looking for. It would have been nice if this had been documented.

Hello Uno, try to set the Angle to 90 degrees

oCell.RotateAngle = 9000

I tried that, but then I get an AtributeError as described in the question.

sorry it only works for Calc cells, like @Lupp said in his answer above.

I don’t think there is a general rotation for cells of tables in ‘Writer’. Cells supporting the service com.sun.star.sheet.SheetCell (‘Calc’) can accept an angle of rotation for displaying their content or results. In ‘Writer’ you only can use a character property (under ‘Position’ in the UI) rotating by 90° or 270 ° (default: 0°) as far as I know.

(I don’t know about tables in ‘Draw’ / ‘Impress’. Never use them.)

If I select a cell in the UI, then select Table XXX, there is a tab Text Flow. In that tab there is an option Text orientation, with options Horizontal, Vertical and Use superordinate object settings. If I select Vertical, the text is rotated by 90 degrees. This is what I would like to achieve using pyuno.

Yes. I assumed this setting would also go to the character property i mentioned. That’s not the case as I just tested. (Strange effects if mixed.) Anyway I cannot find either a property for the orientation on the cell level nor on the character level. What i tried was eiher without an effect or caused an error. I’m lost and have to give in.

(And I won’t come back to the AOI specials concerning ‘Writer’ text an tables. It’s too frustrating.)