| OpenOffice programming with C# / .net |
| Written by Lars Behrmann | |||
| Tuesday, 27 December 2005 | |||
|
This guide will show how simple it is to develop applications that use OpenOffice. The guide starts with About OpenOffice and .net / C#, Setup Microsoft Visual Studio .net 2002/2003 for OpenOffice programming, your first application, ...
OpenOffice programming with C# / .net A quick start guide
Author: Lars Behrmann Email: This e-mail address is being protected from spam bots, you need JavaScript enabled to view it '; document.write( '' ); document.write( addy_text40614 ); document.write( '<\/a>' ); //-->\n This e-mail address is being protected from spam bots, you need JavaScript enabled to view it WWW: http://www.OpenDocument4all.com
Table of Contents
OpenOffice is a free available Office Suite which is based on Suns StarOffice. This is one of the reasons why OpenOffice is really stable and full of features, so that you would miss nothing if you move from Microsoft Office to OpenOffice. The acceptance of OpenOffice is increasing day by day. So you should give it a chance and try it out. I think many IT decision maker of companies think about moving from Microsoft Office to OpenOffice, because they could save a lot of money and since OpenOffice version 2.0 there isn't really a need for a employee training. The Gui handling since OpenOffice 2.0 is very similar to Microsoft Office. So why they don't move to OpenOffice? I guess they stuck on Microsoft Office, because they have too many in house IT solutions which need Microsoft Office to run. If this solutions could changed to accept both Microsoft Office and OpenOffice I think many companies would move! OK, it will cost some development time and so also money to realize this, but it is a one time cost. Since OpenOffice version 2.0 this costs could be downcast to a minimum, because OpenOffice offer since this version a .net based programming interface. Which are represented by the CLI assemblies which are part of each OpenOffice installation. It's quite easy for a .net developer to reference this assemblies and write applications that communicate and interact with OpenOffice. Yes, that is all! There is no need of SDK installation it will run simply by referencing the assemblies. This is a really advantage against other languages like C++ or Java. 2. Setting up a first project with Microsoft Visual Studio .net 2002/2003 Requirements for this next steps are that you have already a installation of a OpenOffice version greater resp. equal 2.0 and you use Microsoft Visual Studio .net 2002/2003 as development IDE.
That's all. Now, you are ready to write your first application. As first application we would programming a simple application which connect to an running OpenOffice instance and if OpenOffice isn't already running it will start a new instance. If the application is connected we create a service handler to communicate with OpenOffice and use it to get access to the OpenOffice desktop. If we receive the desktop instance we will start a blank text document. In this blank document we write some simple text and at least the document should be saved. I think the best way is, if I will show you the whole source code of this application. It isn't really long and I will place self speaking comments inside the code. So let's see the code.
Table 1: Source code of first application Simple copy this code into the clipboard and replace your class which contain the Main method. Now, you could hit F5 to start the application in Debug mode. It should compile without an error. After the application is started OpenOffice should be started and displaying first a blank writer document into which will immediately written our text. At least the document will be saved. All these steps are so fast that it will look like one single step, but I think that should be no problem ;) I think was a good starting point for your career as OpenOffice .net developer. Feel free to use this simple application code to experiment with other features of OpenOffice programming. 3.2 The source code using “Reflection” Now, I will show you how to do the same, but don't using the CLI assemblies. Instead of the CLI assemblies we use the Reflection and Interop technology. This will only quick view on how to develop for versions down OpenOffice 2.0. You will see this isn't nearly as comfortable as the CLI way, but if you have to develop applications for OpenOffice versions 1.1.x.x you will have no other choice. Here comes the code.
Table 2: Source code of first application using Reflection As you can see OpenOffice programming this way is also possible, but I guess it's the hard way. There's no Intellisense support for our objects. You must know every property and mehod. You should use this only if it's really necessary. If you want to develop more applications using OpenOffice you will need further help. For further help you could use the UNO online help pages which are always up to date and the UNO Developers Guide. If you download the UNO SDK from OpenOffice you could view all this material also offline.
To be continued .. Download: As PDF, as OpenDocument
Lars Behrmann, This e-mail address is being protected from spam bots, you need JavaScript enabled to view it '; document.write( '' ); document.write( addy_text40614 ); document.write( '<\/a>' ); //-->\n This e-mail address is being protected from spam bots, you need JavaScript enabled to view it , last Update 28. December 2006 |
|||
| Last Updated ( Wednesday, 28 December 2005 ) | |||