You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@openoffice.apache.org by Xiao Ting Xiao <ti...@gmail.com> on 2012/08/23 03:19:21 UTC

How to insert Table with AutoCaption in swriter?

Hi all,

I want to use UNO api to verify swriter's AutoCaption configuration.
In order to whether it is feasible, I made the following steps:

Step 1,
I manually configure swriter's AutoCaption via menu
Tools-->Options-->OpenOffice.org Writer-->AutoCaption, check
"OpenOffice.org Writer Table" to automatically add caption when inserting
table.

Step 2,
I run the following script to insert table via UNO api, but caption was not
added automatically.

        XComponent xComponent = unoApp.newDocument("swriter");
        XTextDocument xTextDocument
=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, xComponent);
        XText xText = xTextDocument.getText();
        XTextCursor xTextCursor = xText.createTextCursor();
        XMultiServiceFactory xWriterFactory
=(XMultiServiceFactory)UnoRuntime.queryInterface(XMultiServiceFactory.class,
xTextDocument);
        XTextTable xTable =
(XTextTable)UnoRuntime.queryInterface(XTextTable.class,
xWriterFactory.createInstance("com.sun.star.text.TextTable"));
        xText.insertTextContent(xTextCursor,xTable,false);

Is there extra operation I need to do? or it is not feasible to verify
AutoCaption configuration via UNO api?

Thanks your response.

Re: How to insert Table with AutoCaption in swriter?

Posted by Xiao Ting Xiao <ti...@gmail.com>.
Thanks a lot,  chengjh.
It's very helpful. I'll not waste time on this test via UNO api.

On Thu, Aug 23, 2012 at 3:04 PM, chengjh <ch...@apache.org> wrote:

> HI Xiao Ting,
>
> As I know, currently, it seems not able to do as you expect..The option
> settings are stored in class SwModuleOptions, which defines a variable
> named by "pModuleConfig" in class SwModule,accessible
> globally.Theoretically, the pair APIs "setPropertyValue"
> and "getPropertyValue" provided by css::beans::XPropertySet can be used to
> set/get the certain settings,such as the AutoCaption configuration
> because css::beans::XPropertySet is a parent interface of
> SwXTextDocument,equal position with XTextDocument mentioned in your code
> segment..Developers can get its instance from the similar code segment as
> below.Please double confirm because I didn't code or verify..
>
> XComponent xComponent = unoApp.newDocument("swriter");
> XPropertySet xPS = ( XPropertySet  )UnoRuntime.queryInterface(
> XPropertySet.class, xComponent);
>
>
> Unfortunately,the implementations of  "setPropertyValue"
> and "getPropertyValue" in class SwXTextDocument don't provide the code to
> set/get the AutoCaption configuration value. Hope it helpful for you..
>
> On Thu, Aug 23, 2012 at 9:19 AM, Xiao Ting Xiao <ti...@gmail.com>
> wrote:
>
> > Hi all,
> >
> > I want to use UNO api to verify swriter's AutoCaption configuration.
> > In order to whether it is feasible, I made the following steps:
> >
> > Step 1,
> > I manually configure swriter's AutoCaption via menu
> > Tools-->Options-->OpenOffice.org Writer-->AutoCaption, check
> > "OpenOffice.org Writer Table" to automatically add caption when inserting
> > table.
> >
> > Step 2,
> > I run the following script to insert table via UNO api, but caption was
> not
> > added automatically.
> >
> >         XComponent xComponent = unoApp.newDocument("swriter");
> >         XTextDocument xTextDocument
> > =(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class,
> xComponent);
> >         XText xText = xTextDocument.getText();
> >         XTextCursor xTextCursor = xText.createTextCursor();
> >         XMultiServiceFactory xWriterFactory
> >
> >
> =(XMultiServiceFactory)UnoRuntime.queryInterface(XMultiServiceFactory.class,
> > xTextDocument);
> >         XTextTable xTable =
> > (XTextTable)UnoRuntime.queryInterface(XTextTable.class,
> > xWriterFactory.createInstance("com.sun.star.text.TextTable"));
> >         xText.insertTextContent(xTextCursor,xTable,false);
> >
> > Is there extra operation I need to do? or it is not feasible to verify
> > AutoCaption configuration via UNO api?
> >
> > Thanks your response.
> >
>
>
>
> --
>
> Best Regards,Jianhong Cheng
>

Re: How to insert Table with AutoCaption in swriter?

Posted by chengjh <ch...@apache.org>.
HI Xiao Ting,

As I know, currently, it seems not able to do as you expect..The option
settings are stored in class SwModuleOptions, which defines a variable
named by "pModuleConfig" in class SwModule,accessible
globally.Theoretically, the pair APIs "setPropertyValue"
and "getPropertyValue" provided by css::beans::XPropertySet can be used to
set/get the certain settings,such as the AutoCaption configuration
because css::beans::XPropertySet is a parent interface of
SwXTextDocument,equal position with XTextDocument mentioned in your code
segment..Developers can get its instance from the similar code segment as
below.Please double confirm because I didn't code or verify..

XComponent xComponent = unoApp.newDocument("swriter");
XPropertySet xPS = ( XPropertySet  )UnoRuntime.queryInterface(
XPropertySet.class, xComponent);


Unfortunately,the implementations of  "setPropertyValue"
and "getPropertyValue" in class SwXTextDocument don't provide the code to
set/get the AutoCaption configuration value. Hope it helpful for you..

On Thu, Aug 23, 2012 at 9:19 AM, Xiao Ting Xiao <ti...@gmail.com> wrote:

> Hi all,
>
> I want to use UNO api to verify swriter's AutoCaption configuration.
> In order to whether it is feasible, I made the following steps:
>
> Step 1,
> I manually configure swriter's AutoCaption via menu
> Tools-->Options-->OpenOffice.org Writer-->AutoCaption, check
> "OpenOffice.org Writer Table" to automatically add caption when inserting
> table.
>
> Step 2,
> I run the following script to insert table via UNO api, but caption was not
> added automatically.
>
>         XComponent xComponent = unoApp.newDocument("swriter");
>         XTextDocument xTextDocument
> =(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, xComponent);
>         XText xText = xTextDocument.getText();
>         XTextCursor xTextCursor = xText.createTextCursor();
>         XMultiServiceFactory xWriterFactory
>
> =(XMultiServiceFactory)UnoRuntime.queryInterface(XMultiServiceFactory.class,
> xTextDocument);
>         XTextTable xTable =
> (XTextTable)UnoRuntime.queryInterface(XTextTable.class,
> xWriterFactory.createInstance("com.sun.star.text.TextTable"));
>         xText.insertTextContent(xTextCursor,xTable,false);
>
> Is there extra operation I need to do? or it is not feasible to verify
> AutoCaption configuration via UNO api?
>
> Thanks your response.
>



-- 

Best Regards,Jianhong Cheng