Unable to add field in table

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
arpit.gupta
Posts: 1
Joined: Fri Dec 23, 2011 11:18 am

Unable to add field in table

Post by arpit.gupta »

Hello Friends,

I am trying to insert a field into a document at the current cursor location with the following code:

Code: Select all


      OpenOfficeDoc textDocument = getCurrentClientSite(); 
      OpenOfficeField myNewPlaceholder = textDocument.createUserField(fieldName, fieldValue); 
      XText xText = textDocument.getXTextDocument().getText(); 

      //GET THE CURRENT LOCATION 
      XController xController = textDocument.getXTextDocument().getCurrentController(); 
      XTextViewCursorSupplier xTextViewCursorSupplier = (XTextViewCursorSupplier)UnoRuntime.queryInterface(XTextViewCursorSupplier.class, xController); 

      //INSERT INTO THE TEXT CONTENT 
      xText.insertTextContent(xTextViewCursorSupplier.getViewCursor().getStart(), myNewPlaceholder.getxDependentTextField(), true); 

In general this works fine. However when the cursor is inside a table the following exception is thrown :

uno.com.sun.star.uno.RuntimeException: text interface and cursor not related

i tried to figure it out but with no luck.
Can someone please help me why this error is coming.

Thanks,
Arpit
OpenOffice 3.1 on Windows 7
hanya
Volunteer
Posts: 885
Joined: Fri Nov 23, 2007 9:27 am
Location: Japan

Re: Unable to add field in table

Post by hanya »

Hi,
Welcome to the forum.

There are some XText reference in the text document. Your xText variable is bound to the body of the document but there is another XText reference for your table. Therefore, get the reference to XText interface from the same context (the table in this case) of the text range passed as first argument of the insertTextContent. Simply, get it from the view cursor.
Please, edit this thread's initial post and add "[Solved]" to the subject line if your problem has been solved.
Apache OpenOffice 4-dev on Xubuntu 14.04
oliveiratr
Posts: 30
Joined: Thu Dec 29, 2016 12:22 pm

Re: Unable to add field in table

Post by oliveiratr »

Can u give any example ?
OpenOffice 4.1.2
Post Reply