The following Java has been generated by the
MRI extension:
Code: Select all
import com.sun.star.beans.PropertyValue;
import com.sun.star.container.XIndexAccess;
import com.sun.star.container.XNameAccess;
import com.sun.star.lang.IndexOutOfBoundsException;
import com.sun.star.lang.WrappedTargetException;
import com.sun.star.text.XTextTable;
import com.sun.star.text.XTextTablesSupplier;
import com.sun.star.uno.UnoRuntime;
import com.sun.star.uno.XComponentContext;
import com.sun.star.util.XSortable;
public static void snippet(XComponentContext xComponentContext, Object oInitialTarget)
{
try
{
XTextTablesSupplier xTextTablesSupplier = UnoRuntime.queryInterface(
XTextTablesSupplier.class, oInitialTarget);
XNameAccess xNameAccess = xTextTablesSupplier.getTextTables();
XIndexAccess xIndexAccess = UnoRuntime.queryInterface(
XIndexAccess.class, xNameAccess);
XTextTable xTextTable = UnoRuntime.queryInterface(
XTextTable.class, xIndexAccess.getByIndex(0));
XSortable xSortable = UnoRuntime.queryInterface(
XSortable.class, xTextTable);
PropertyValue[] aPropertyValue = xSortable.createSortDescriptor();
}
catch (WrappedTargetException e1)
{
// getByIndex
e1.printStackTrce();
}
catch (IndexOutOfBoundsException e2)
{
// getByIndex
e2.printStackTrce();
}
}
The TextTable supports service com.sun.star.text.TextSortable so you have to query that interface from the TextTable:
XSortable xSortable = UnoRuntime.queryInterface(XSortable.class, xTextTable);
Same in C++
Code: Select all
#include <com/sun/star/beans/PropertyValue.hpp>
#include <com/sun/star/container/XIndexAccess.hpp>
#include <com/sun/star/container/XNameAccess.hpp>
#include <com/sun/star/text/XTextTable.hpp>
#include <com/sun/star/text/XTextTablesSupplier.hpp>
#include <com/sun/star/uno/XComponentContext.hpp>
#include <com/sun/star/uno/XInterface.hpp>
#include <com/sun/star/util/XSortable.hpp>
using namespace ::com::sun::star::beans;
using namespace ::com::sun::star::container;
using namespace ::com::sun::star::lang;
using namespace ::com::sun::star::text;
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::util;
using namespace ::rtl;
void snippet(const Reference< XComponentContext > &xContext, const Reference< XInterface > &oInitialTarget)
{
try
{
Reference< XTextTablesSupplier > xTextTablesSupplier(oInitialTarget, UNO_QUERY);
Reference< XNameAccess > xNameAccess = xTextTablesSupplier->getTextTables();
Reference< XIndexAccess > xIndexAccess(xNameAccess, UNO_QUERY);
Reference< XTextTable > xTextTable(xIndexAccess->getByIndex(0), UNO_QUERY);
Reference< XSortable > xSortable(xTextTable, UNO_QUERY);
Sequence< PropertyValue > aPropertyValue = xSortable->createSortDescriptor();
}
catch (WrappedTargetException &e)
{
// getByIndex
//printf(OUStringToOString(e.Message, RTL_TEXTENCODING_ASCII_US).getStr());
}
catch (IndexOutOfBoundsException &e)
{
// getByIndex
//printf(OUStringToOString(e.Message, RTL_TEXTENCODING_ASCII_US).getStr());
}
}