Compare 2 documents using C# code and OOo Writer API

Java, C++, C#, Delphi... - Using the UNO bridges
Post Reply
pasareflorin
Posts: 1
Joined: Tue Feb 19, 2008 7:19 pm
Location: Bucharest, Romania

Compare 2 documents using C# code and OOo Writer API

Post by pasareflorin »

I read other threads (in the old forum), about how to compare 2 docs using vbasic but didn't help me much. (http://www.oooforum.org/forum/viewtopic ... ompare+doc)

I'm a begginer in OOo api so if anybody can help me with my problem please do so.

I want to compare 2 documents in Writer using C# code and the OOo api. If someone can post the code on how to do this pls help (or can suggest a place where I could read about this - the OOo documentation is using java and I am a C# user :().

Thanks in advance!

I've been working on this task and this is what I have so far:

//Get a ComponentContext
xLocalContext = uno.util.Bootstrap.bootstrap();
//Get MultiServiceFactory
unoidl.com.sun.star.lang.XMultiServiceFactory xRemoteFactory =
(unoidl.com.sun.star.lang.XMultiServiceFactory)xLocalContext.getServiceManager();
//Get a ComponentLoader
aLoader = (XComponentLoader)xRemoteFactory.createInstance("com.sun.star.frame.Desktop");

XDesktop desktop = (XDesktop)xRemoteFactory.createInstance("com.sun.star.frame.Desktop");
unoidl.com.sun.star.beans.PropertyValue[] Args = new unoidl.com.sun.star.beans.PropertyValue[1];
XComponent Document1 = aLoader.loadComponentFromURL(@"file:///C:/copy of temp.doc", "_blank", 0, Args);

unoidl.com.sun.star.frame.XFrame Frame = desktop.getCurrentFrame();

//Create the Dispatcher
unoidl.com.sun.star.frame.XDispatchHelper Dispatcher = (XDispatchHelper)xRemoteFactory.createInstance("com.sun.star.frame.DispatchHelper");

unoidl.com.sun.star.beans.PropertyValue[] propertyValue = new unoidl.com.sun.star.beans.PropertyValue[3];
propertyValue[0] = new unoidl.com.sun.star.beans.PropertyValue();
propertyValue[0].Name = "ShowTrackedChanges";
propertyValue[0].Value = new uno.Any(typeof(Boolean), true);

Dispatcher.executeDispatch((XDispatchProvider)Frame, ".uno:ShowTrackedChanges", "", 0, propertyValue);

unoidl.com.sun.star.beans.PropertyValue[] propertyValueFile = new unoidl.com.sun.star.beans.PropertyValue[1];
propertyValueFile[0] = new unoidl.com.sun.star.beans.PropertyValue();
propertyValueFile[0].Name = "URL";
propertyValueFile[0].Value = new uno.Any(@"file:///C:/temp.doc");

Dispatcher.executeDispatch((XDispatchProvider)Frame, ".uno:CompareDocuments", "", 0, propertyValueFile);

//save the document
SaveToDisk(@"C:\copy of temp.doc", @"C:\tempmod.doc", SaveFormatTypeEnum.doc, Document1);


This code is working ok, but if i want to make this without the OOo UI, it doesn't work.
I make the UI invisible using this:

unoidl.com.sun.star.beans.PropertyValue[] Args = new unoidl.com.sun.star.beans.PropertyValue[1];
Args[0] = new PropertyValue();
Args[0].Name = "Hidden";
Args[0].Value.setValue(typeof(Boolean), true);
XComponent Document1 = aLoader.loadComponentFromURL(@"file:///C:/copy of temp.doc", "_blank", 0, Args);


I think that the dispatcher is related to the UI or something like that... I don't know.

If somebody can show me how can I make this work, please help!

If I find anything new I'll edit my post.
User avatar
foxcole
Volunteer
Posts: 1507
Joined: Mon Oct 08, 2007 1:31 am
Location: Minneapolis, Minnesota

Re: Compare 2 documents using C# code and OOo Writer API

Post by foxcole »

Wow.. posted five months ago, and still no reply. :(
Did you ever figure this out, or perhaps find a better way?
Cheers!
---Fox

OOo 3.2.0 Portable, Windows 7 Home Premium 64-bit
mcyep
Posts: 1
Joined: Sun Nov 29, 2009 6:40 pm

Re: Compare 2 documents using C# code and OOo Writer API

Post by mcyep »

pasareflorin wrote: .....

This code is working ok, but if i want to make this without the OOo UI, it doesn't work.
I make the UI invisible using this:

unoidl.com.sun.star.beans.PropertyValue[] Args = new unoidl.com.sun.star.beans.PropertyValue[1];
Args[0] = new PropertyValue();
Args[0].Name = "Hidden";
Args[0].Value.setValue(typeof(Boolean), true);
XComponent Document1 = aLoader.loadComponentFromURL(@"file:///C:/copy of temp.doc", "_blank", 0, Args);


I think that the dispatcher is related to the UI or something like that... I don't know.

If somebody can show me how can I make this work, please help!

If I find anything new I'll edit my post.
I make it by change:

unoidl.com.sun.star.beans.PropertyValue[] Args = new unoidl.com.sun.star.beans.PropertyValue[1];
Args[0] = new unoidl.com.sun.star.beans.PropertyValue();
Args[0].Name = "Hidden";
Args[0].Value = new uno.Any(typeof(Boolean), true);
OpenOffice 3.1 on Windows XP
Post Reply