Ask Your Question
0

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 = com.sun.star.table.CellVertJustify.CENTER

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("com.sun.star.text.TextTable"));
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" com.sun.star.beans.UnknownPropertyException: 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
1

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

librebel gravatar image

Hello ksten, Google doesn't recognize the difference between com.sun.star.text.CellProperties and com.sun.star.table.CellProperties

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 = com.sun.star.style.ParagraphAdjust.CENTER
edit flag offensive delete link more

Comments

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 = com.sun.star.text.ParagraphVertAlign.CENTER
librebel gravatar imagelibrebel ( 2017-05-22 08:12:38 +0200 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

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

Seen: 170 times

Last updated: May 22 '17