Get XTextTable from current cursor position.

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
etrix
Posts: 2
Joined: Sat Feb 11, 2017 7:56 am

Get XTextTable from current cursor position.

Post by etrix »

Hi, is it possible to get a XTextTable object from the current cursor position?
I'm going to search for matching words in the document text and check if those words are inside table cells, then modify the matching words and also insert new rows.
I'm using c++ bindings.
OpenOffice 4 on Windows 10
F3K Total
Volunteer
Posts: 1038
Joined: Fri Dec 16, 2011 8:20 pm

Re: Get XTextTable from current cursor position.

Post by F3K Total »

Hi,
maybe the basic code helps:

Code: Select all

Sub get_currentTexttable
     oController = ThisComponent.CurrentController
     oViewCursor = oController.getViewCursor
     if not isEmpty(oViewCursor.TextTable) then
         oTextTable = oViewCursor.TextTable 'oTexttable is the object
         print oTextTable.Name
     end if  
End Sub
  • MMove 1.0.6
  • Extension for easy, exact positioning of shapes, pictures, controls, frames ...
  • my current system
  • Windows 10 AOO, LOLinux Mint AOO, LO
etrix
Posts: 2
Joined: Sat Feb 11, 2017 7:56 am

Re: Get XTextTable from current cursor position.

Post by etrix »

How am I writing this in c++?
Im having a hard time to understand how I'm supposed to write all those basic examples in c++.
I can't really find any good information about this.
OpenOffice 4 on Windows 10
FJCC
Moderator
Posts: 9280
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: Get XTextTable from current cursor position.

Post by FJCC »

I recorded the commands to get the TextTable object in C++ with MRI.

Code: Select all

#include <com/sun/star/beans/XPropertySet.hpp>
#include <com/sun/star/frame/XController.hpp>
#include <com/sun/star/frame/XModel.hpp>
#include <com/sun/star/text/XTextTable.hpp>
#include <com/sun/star/text/XTextViewCursor.hpp>
#include <com/sun/star/text/XTextViewCursorSupplier.hpp>
#include <com/sun/star/uno/XComponentContext.hpp>
#include <com/sun/star/uno/XInterface.hpp>

using namespace ::com::sun::star::beans;
using namespace ::com::sun::star::frame;
using namespace ::com::sun::star::lang;
using namespace ::com::sun::star::text;
using namespace ::com::sun::star::uno;
using namespace ::rtl;

void snippet(const Reference< XComponentContext > &xContext, const Reference< XInterface > &oInitialTarget)
{
    try
    {
        Reference< XModel > xModel(oInitialTarget, UNO_QUERY);
        Reference< XController > xController = xModel->getCurrentController();
        
        Reference< XTextViewCursorSupplier > xTextViewCursorSupplier(xController, UNO_QUERY);
        Reference< XTextViewCursor > xTextViewCursor = xTextViewCursorSupplier->getViewCursor();
        
        Reference< XPropertySet > xPropSet(xTextViewCursor, UNO_QUERY);
        XTextTable xTextTable;
        xPropSet->getPropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM("TextTable"))) >>= xTextTable;
        
    }
    catch (WrappedTargetException &e)
    {
        // getPropertyValue
        //printf(OUStringToOString(e.Message, RTL_TEXTENCODING_ASCII_US).getStr());
    }
    catch (UnknownPropertyException &e)
    {
        // getPropertyValue
        //printf(OUStringToOString(e.Message, RTL_TEXTENCODING_ASCII_US).getStr());
    }
}
I don't do C++ but I hope that helps. The equivalent in Basic is

Code: Select all

  oCurrentController = ThisComponent.getCurrentController()
  oViewCursor = oCurrentController.getViewCursor()
  oTextTable = oViewCursor.TextTable
OpenOffice 4.1 on Windows 10 and Linux Mint
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
Post Reply