OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

How To Invoke a OOoBasic Script (not Macro) in Java

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API
View previous topic :: View next topic  
Author Message
zzeric
General User
General User


Joined: 08 Apr 2010
Posts: 5

PostPosted: Thu Apr 08, 2010 10:10 pm    Post subject: How To Invoke a OOoBasic Script (not Macro) in Java Reply with quote

Hello all, I want to get the page count of the document in java.

Here is the way with XPageCursor, but it's limited, just suitable for the documents opened with Writer. The other files such as xls, it doesn't work.

Code:
private static short getPageCount(XComponent xComp) {
      XModel xModel = (XModel) UnoRuntime.queryInterface(XModel.class, xComp);
      XController xController = xModel.getCurrentController();
      XTextViewCursorSupplier xViewCursorSupplier = (XTextViewCursorSupplier) UnoRuntime
            .queryInterface(XTextViewCursorSupplier.class, xController);
      XPageCursor pageCursor = (XPageCursor) UnoRuntime.queryInterface(
            XPageCursor.class, xViewCursorSupplier.getViewCursor());
      pageCursor.jumpToLastPage();
      return pageCursor.getPage();
   }


I searched and found I could get the page count with OOoBasic "ThisComponent.CurrentController.PageCount", so I used XScript to invoke it.
Code:

        XScriptProviderSupplier xScriptPS = (XScriptProviderSupplier)UnoRuntime.queryInterface(XScriptProviderSupplier.class, xComp);
        XScriptProvider xScriptProvider = xScriptPS.getScriptProvider();
        XScript xScript = xScriptProvider.getScript("vnd.sun.star.script:Standard.Module1.ThisComponent.CurrentController.PageCount?language=Basic&location=application");
       
        short[][] aOutParamIndex = new short[1][1];
        Object[][] aOutParam  = new Object[1][1];
        xScript.invoke(null, aOutParamIndex, aOutParam);


The code will throw exception
Code:

Exception in thread "main" com.sun.star.script.provider.ScriptFrameworkErrorException: The following Basic script could not be found:
library: 'Standard'
module: 'Module1'
method: 'ThisComponent'
location: 'application'


So how to invoke this script ? Thanks
Back to top
View user's profile Send private message
zzeric
General User
General User


Joined: 08 Apr 2010
Posts: 5

PostPosted: Fri Apr 09, 2010 12:52 am    Post subject: Reply with quote

I wrote a OOoBasic macro
Code:

Sub PageCount
       MsgBox ThisComponent.CurrentController.PageCount
End Sub


and found it also just work in Writer, but Calc
Back to top
View user's profile Send private message
B Marcelly
Super User
Super User


Joined: 12 May 2004
Posts: 1453
Location: France

PostPosted: Fri Apr 09, 2010 1:12 am    Post subject: Reply with quote

Hi,
Quote:
I searched and found I could get the page count with OOoBasic "ThisComponent.CurrentController.PageCount", so I used XScript to invoke it.

This property of com.sun.star.text.TextDocumentView is only valid for text documents. Not spreadsheets.
You can get the current controller of a text document and its PageCount property from Java, no need to call a macro.
_________________
Bernard

OpenOffice.org 1.1.5 fr / Apache OpenOffice 4.0.1 / LibreOffice 4.1.0
MS-Windows 7 Home SP1
This forum is spammed, use instead Apache OpenOffice forums
Back to top
View user's profile Send private message Visit poster's website
zzeric
General User
General User


Joined: 08 Apr 2010
Posts: 5

PostPosted: Sun Apr 11, 2010 12:40 am    Post subject: Reply with quote

B Marcelly wrote:
Hi,
Quote:
I searched and found I could get the page count with OOoBasic "ThisComponent.CurrentController.PageCount", so I used XScript to invoke it.

This property of com.sun.star.text.TextDocumentView is only valid for text documents. Not spreadsheets.
You can get the current controller of a text document and its PageCount property from Java, no need to call a macro.


Yes, thanks.
Exactly, I want to find a way to get a page count for files opened by Writer/Calc/Impress.
It seems it is impossible by now. Threre is several way to get the page count in Writer(PageCursor / PropertySet / DocumentStatistic / Macro), but all these ways do not apply at Calc and Impress. That is very strange, why not OO does not supply a same api to do something to the files, such as file statistics.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group