I am working on Java API which interacts with OpenOffice(swriter) through UNO.
For TextTable, I am having hard time setting TableColumn’s “OptimalWidth” property.
I have tried the following code and it seems that getColumns() method cannot take me to TableColumn’s property and let you only insert and remove columns.
XTableColumns xColumns = xTextTable.getColumns();
XIndexAccess xIndexAccess = (XIndexAccess) UnoRuntime.queryInterface(
XIndexAccess.class, xColumns);
for (int i = 0; i < xIndexAccess.getCount(); i++) {
XPropertySet xColumnProps = (XPropertySet) UnoRuntime
.queryInterface(XPropertySet.class,
(Any) xIndexAccess.getByIndex(i));
if (xColumnProps != null) {
xColumn.setPropertyValue("OptimalWidth", new Boolean(true));
}
}
Can anyone help me out or give me any tips setting OptimalWidth property for a table?
Thank you very much in advance!
It was quite an odyssey to find out, but I finally managed to create a function which does exactly that:
It is important that the dispatchHelper comes from the OpenOffice context, and not from the current document. I retrieved the dispatchHelper this way: