| View previous topic :: View next topic |
| Author |
Message |
zzeric General User

Joined: 08 Apr 2010 Posts: 5
|
Posted: Thu Apr 08, 2010 10:10 pm Post subject: How To Invoke a OOoBasic Script (not Macro) in Java |
|
|
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 |
|
 |
zzeric General User

Joined: 08 Apr 2010 Posts: 5
|
Posted: Fri Apr 09, 2010 12:52 am Post subject: |
|
|
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 |
|
 |
B Marcelly Super User

Joined: 12 May 2004 Posts: 1414 Location: France
|
Posted: Fri Apr 09, 2010 1:12 am Post subject: |
|
|
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 / OpenOffice.org 3.4.1 en-US + langpacks, MS-Windows XP Home SP3
This forum is unusable, use instead Apache OpenOffice forums |
|
| Back to top |
|
 |
zzeric General User

Joined: 08 Apr 2010 Posts: 5
|
Posted: Sun Apr 11, 2010 12:40 am Post subject: |
|
|
| 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 |
|
 |
|
|
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
|