I want to create a table in a Writer document. For this, I am doing the following:
Reference<XComponentContext> xContext(::cppu::bootstrap());
Reference<XMultiComponentFactory> xServiceManager = xContext->getServiceManager();
Reference<XInterface> xDesktop = xServiceManager->createInstanceWithContext(OUString("com.sun.star.frame.Desktop"), xContext);
Reference<XDesktop2> xDesktop2(xDesktop, UNO_QUERY_THROW);
Reference<XComponent> xComponent = xDesktop2->loadComponentFromURL(
"private:factory/swriter",
OUString::createFromAscii("_blank"), 0,
Sequence <::com::sun::star::beans::PropertyValue>());
Reference<XTextDocument> xTextDocument(xComponent, UNO_QUERY_THROW);
try {
Reference<XMultiComponentFactory> xServiceFactory(xContext->getServiceManager());
// Create a new text table
Reference<XInterface> xInterface(xServiceFactory>createInstanceWithContext("com.sun.star.text.TextTable", xContext));
// Query for the XTextTable interface
Reference<XTextTable> xTextTable(xInterface, UNO_QUERY_THROW);
// Check if the query was successful
if (xTextTable.is()) {
// Interface query succeeded, proceed with your operations
// ...
fprintf(stdout, "XTextTable is\n");
}
else
{
// Interface query failed
fprintf(stdout, "failed to query XTextTable interface\n");
}
}
catch (Exception& e)
{
fprintf(stdout, "exception: %s\n", OUStringToOString(e.Message, RTL_TEXTENCODING_UTF8).getStr());
}
But I get a runtime exception: unsatisfied query for interface of type com.sun.star.text.XTextTable!
What am I doing wrong here?