Ask Your Question

How do I access a cell's VertJustify in Java?

asked 2017-05-22 05:29:42 +0200

ksten gravatar image

When I search for this on Google, it gives examples in the macro language like this:

Cell.VertJustify =

However when I try something similar in Java:

XTextDocument document = getDocument();
XMultiServiceFactory serviceFactory = UnoRuntime.queryInterface(XMultiServiceFactory.class, document);
XTextTable table = UnoRuntime.queryInterface(XTextTable.class, serviceFactory.createInstance(""));
table.initialize(1, 1);
XPropertySet properties = UnoRuntime.queryInterface(XPropertySet.class, table);
properties.setPropertyValue("HoriOrient", HoriOrientation.FULL);
document.getText().insertTextContent(cursor, table, false);
XCell cell = table.getCellByName("A1");
XText cellText = UnoRuntime.queryInterface(XText.class, cell);
XTextCursor cellCursor = cellText.createTextCursor();
cellText.insertString(cellCursor, "This is a test", false);
properties = UnoRuntime.queryInterface(XPropertySet.class, cell);
properties.setPropertyValue("BottomBorderDistance", Units.inchesToHundredthsMm(7));
properties.setPropertyValue("VertJustify", CellVertJustify.CENTER);

It throws an exception: Exception in thread "main" VertJustify

What I'm trying to do is center some text both vertically and horizontally on a page in my writer document.

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted

answered 2017-05-22 06:57:18 +0200

librebel gravatar image

Hello ksten, Google doesn't recognize the difference between and

VertJustify is for Calc cells, you have a text table cell. As pointed out by the creator of Xray in this post, you can alter the justfication inside a text table cell by using an ordinary paragraph style, e.g. :

cellCursor.ParaAdjust =
edit flag offensive delete link more


That's for horizontal centering. I need vertical centering.

ksten gravatar imageksten ( 2017-05-22 07:28:54 +0200 )edit

yes, you can lookup the available properties here, then you see the property "ParaVertAlignment" , then you could type this:

cellCursor.ParaVertAlignment =
librebel gravatar imagelibrebel ( 2017-05-22 08:12:38 +0200 )edit
Login/Signup to Answer

Question Tools

1 follower


Asked: 2017-05-22 05:29:42 +0200

Seen: 167 times

Last updated: May 22 '17