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

Problem with Macro to insertField

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


Joined: 10 Nov 2005
Posts: 16
Location: FRANCE

PostPosted: Tue Nov 15, 2005 6:34 am    Post subject: Problem with Macro to insertField Reply with quote

I've got a problem when I want insert a new field in my document.
I want insert a field. This field was created by me and it's the NUMCLI for exemple.
I recorded the macro :
Code:
rem ----------------------------------------------------------------------
rem define variables
dim document   as object
dim dispatcher as object
rem ----------------------------------------------------------------------
rem get access to the document
document   = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")

rem ----------------------------------------------------------------------
dim args1(5) as new com.sun.star.beans.PropertyValue
args1(0).Name = "Type"
args1(0).Value = 20
args1(1).Name = "SubType"
args1(1).Value = 2
args1(2).Name = "Name"
args1(2).Value = "NUMCLI"
args1(3).Name = "Content"
args1(3).Value = "5"
args1(4).Name = "Format"
args1(4).Value = 5000
args1(5).Name = "Separator"
args1(5).Value = " "

dispatcher.executeDispatch(document, ".uno:InsertField", "", 0, args1())


When I execute this macro it's good BUT then I execute this macro in JAVA it's NOT good because it inserts the date...
I don't understand!!!
Help me

It's my code in JAVA :
Code:
PropertyValue[] propertyvalue2 = new PropertyValue[6];

          propertyvalue2[0] = new PropertyValue();
          propertyvalue2[0].Name = "Type";
          propertyvalue2[0].Value = "20";
         
          propertyvalue2[1] = new PropertyValue();
          propertyvalue2[1].Name = "SubType";
          propertyvalue2[1].Value = "2";
         
          propertyvalue2[2] = new PropertyValue();
          propertyvalue2[2].Name = "Name";
          propertyvalue2[2].Value = "NUMCLI";
         
          propertyvalue2[3] = new PropertyValue();
          propertyvalue2[3].Name = "Content";
          propertyvalue2[3].Value = "5";
         
          propertyvalue2[4] = new PropertyValue();
          propertyvalue2[4].Name = "Format";
          propertyvalue2[4].Value = "5000";
         
          propertyvalue2[5] = new PropertyValue();
          propertyvalue2[5].Name = "Separator";
          propertyvalue2[5].Value = " ";

         XController xController2 = doc.getCurrentController();
          XFrame xFrame2 = xController2.getFrame();
         
         
          XDispatchProvider xDispatchProvider2 = (XDispatchProvider)UnoRuntime.queryInterface(
                XDispatchProvider.class, xFrame2);
         
          Object NewParagraph2 = xDispatchHelper.executeDispatch(
                xDispatchProvider2, ".uno:InsertField", "", 0, propertyvalue2);


THANKS
Back to top
View user's profile Send private message
pitonyak
Administrator
Administrator


Joined: 09 Mar 2004
Posts: 3655
Location: Columbus, Ohio, USA

PostPosted: Tue Nov 15, 2005 8:23 pm    Post subject: Reply with quote

Is the code run against the same document?
_________________
--
Andrew Pitonyak
http://www.pitonyak.org/oo.php
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address
kevFrance
General User
General User


Joined: 10 Nov 2005
Posts: 16
Location: FRANCE

PostPosted: Tue Nov 15, 2005 11:34 pm    Post subject: Reply with quote

Yes , I take the same document to run the code.

But I have found a solution :

Code:
         XMultiServiceFactory mxDocFactory = (XMultiServiceFactory) UnoRuntime.queryInterface(
               XMultiServiceFactory.class, doc );

         XDependentTextField xUserField = (XDependentTextField) UnoRuntime.queryInterface (
               XDependentTextField.class, mxDocFactory.createInstance(
                     "com.sun.star.text.TextField.User") );

         // create a field master
         XPropertySet xMasterPropSet = (XPropertySet)UnoRuntime.queryInterface(
            XPropertySet.class,mxDocFactory.createInstance(
               "com.sun.star.text.FieldMaster.User"));
         
         
         
         int m = xPageCursor.getPage();
         // set user field as Value
         xMasterPropSet.setPropertyValue ("Name", "PAGEDEPART"+m);

         xMasterPropSet.setPropertyValue ("Value", new Integer(m));
         // set user field as Content
   //      xMasterPropSet.setPropertyValue ("Name", "UserFieldText");
   //      xMasterPropSet.setPropertyValue ("Content", "default text string");
   
         // attach the field master to the user field
         xUserField.attachTextFieldMaster (xMasterPropSet);
   
         // insert the user field
   //      xText.insertString ( curText, "UserField: ", false );
         headerText.insertTextContent(headerText.getEnd(), xUserField, false);   
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