| View previous topic :: View next topic |
| Author |
Message |
LarsB OOo Advocate


Joined: 31 Aug 2005 Posts: 445 Location: Hamburg, Germany
|
Posted: Wed Aug 31, 2005 6:23 am Post subject: XBookmarksSupplier instance in C# resp. .net |
|
|
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 |
|
 |
pitonyak Administrator


Joined: 09 Mar 2004 Posts: 3618 Location: Columbus, Ohio, USA
|
|
| Back to top |
|
 |
LarsB OOo Advocate


Joined: 31 Aug 2005 Posts: 445 Location: Hamburg, Germany
|
Posted: Thu Sep 01, 2005 12:36 am Post subject: Thanks |
|
|
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
Lars |
|
| Back to top |
|
 |
pitonyak Administrator


Joined: 09 Mar 2004 Posts: 3618 Location: Columbus, Ohio, USA
|
Posted: Thu Sep 01, 2005 10:54 am Post subject: |
|
|
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 |
|
 |
LarsB OOo Advocate


Joined: 31 Aug 2005 Posts: 445 Location: Hamburg, Germany
|
Posted: Fri Sep 02, 2005 3:13 am Post subject: Thanks |
|
|
Hi,
thanks for the sample code. I've already solved the bookmark problems.
Now, I'm implementing the TextTable object into my API
Lars |
|
| Back to top |
|
 |
Intexture Newbie

Joined: 27 Sep 2005 Posts: 3 Location: Pakistan
|
Posted: Tue Sep 27, 2005 11:24 pm Post subject: |
|
|
| Now tell me how to set BookMark values in Writer document from C# program |
|
| 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
|