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

XBookmarksSupplier instance in C# resp. .net

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API
View previous topic :: View next topic  
Author Message
LarsB
OOo Advocate
OOo Advocate


Joined: 31 Aug 2005
Posts: 445
Location: Hamburg, Germany

PostPosted: Wed Aug 31, 2005 6:23 am    Post subject: XBookmarksSupplier instance in C# resp. .net Reply with quote

Hi,

i'm trying to get an instance of XBookmarksSupplier to get all bookmarks
within my document.
At this time i try to create my object like that (but it wouldn't work):

Code:
Object[] parameters = new Object[1];
parameters[0] = "com.sun.star.sdb.XBookmarksSupplier";

// ServiceManagerType = Type
//ServiceManager = object
this.XBookmarksSupplier = this.Office.ServiceManagerType.InvokeMember("createInstance",
            BindingFlags.InvokeMethod, null,
            this.Office.ServiceManager, parameters);


in java i found this code snippet:

Code:
 XBookmarksSupplier xBookmarksSupplier = (XBookmarksSupplier)UnoRuntime.queryInterface(
XBookmarksSupplier.class, xDoc);


how will it work in C#

thanks, Lars
Back to top
View user's profile Send private message Visit poster's website
pitonyak
Administrator
Administrator


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

PostPosted: Wed Aug 31, 2005 11:17 am    Post subject: Reply with quote

I have never used C# to do this, but this may help...

http://www.oooforum.org/forum/viewtopic.phtml?p=90194
_________________
--
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
LarsB
OOo Advocate
OOo Advocate


Joined: 31 Aug 2005
Posts: 445
Location: Hamburg, Germany

PostPosted: Thu Sep 01, 2005 12:36 am    Post subject: Thanks Reply with quote

Hi,

thanks for your reply. I use the same way as described in the snippet to create my
objects. But this wouldn't work with the XBookmarSupplier Sad

Lars
Back to top
View user's profile Send private message Visit poster's website
pitonyak
Administrator
Administrator


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

PostPosted: Thu Sep 01, 2005 10:54 am    Post subject: Reply with quote

Yes, it will. I created a simple C# example, which I will add to my free macro document with a brief explanation on how it is done. This is my first usage to connect to OOo using C# so it is not complicated or complete.
Code:
using System;
using System.Reflection;

namespace ootest
{
   class Class1
   {
      // obj - Invoke a method on this object.
      // method - name of the method to invoke.
      // par - Array of objct arguments
      static object Invoke(object obj,string method, params object[] par)
      {
         return obj.GetType().InvokeMember(method,BindingFlags.InvokeMethod,null,obj,par);
      }

      static void PrintImpName(object obj)
      {
         object x = Invoke(obj, "getImplementationName", new object[0]);
         System.Console.WriteLine(x.ToString());
      }
     
      /// <summary>
      /// The main entry point for the application.
      /// </summary>
      [STAThread]
      public static void Main(string[] args)
      {
         // Get a copy of the service manager.
         object usm=Activator.CreateInstance(Type.GetTypeFromProgID("com.sun.star.ServiceManager"));

         // Create a copy of the desktop. Remember that there is ONLY one.
         object desk=Invoke(usm,"createInstance","com.sun.star.frame.Desktop");
         PrintImpName(desk);

         // The typical example loads a new Calc document
         //object calcDoc=Invoke(desk,"loadComponentFromURL","private:factory/scalc","_blank",0,new object[0]);

         // How about getting the current component? this takes no arguments

         object oDoc = Invoke(desk,"getCurrentComponent", new object[0]);
         PrintImpName(oDoc);
         //System.Threading.Thread.Sleep(1000);

         object x = Invoke(oDoc, "supportsService", "com.sun.star.text.TextDocument");
         if (x is bool && (bool) x)
         {
            System.Console.WriteLine("The current component is a text document");
         }
         else
         {
            System.Console.WriteLine("The current component is NOT a text document");
            System.Threading.Thread.Sleep(10000);
            return;
         }
         object oBookmarks = Invoke(oDoc, "getBookmarks", new object[0]);
         x = Invoke(oBookmarks, "getCount", new object[0]);
         int nCount = (int) x;
         for (int n = 0; n < nCount; ++n)
         {
            object oMark = Invoke(oBookmarks, "getByIndex", n);
            x = Invoke(oMark, "getName", new object[0]);
            System.Console.WriteLine((string) x);
         }

         System.Threading.Thread.Sleep(5000);
      }
   }
}

_________________
--
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
LarsB
OOo Advocate
OOo Advocate


Joined: 31 Aug 2005
Posts: 445
Location: Hamburg, Germany

PostPosted: Fri Sep 02, 2005 3:13 am    Post subject: Thanks Reply with quote

Hi,

thanks for the sample code. I've already solved the bookmark problems.
Now, I'm implementing the TextTable object into my API Very Happy

Lars
Back to top
View user's profile Send private message Visit poster's website
Intexture
Newbie
Newbie


Joined: 27 Sep 2005
Posts: 3
Location: Pakistan

PostPosted: Tue Sep 27, 2005 11:24 pm    Post subject: Reply with quote

Now tell me how to set BookMark values in Writer document from C# program
Back to top
View user's profile Send private message Send e-mail Yahoo Messenger MSN Messenger
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