This Time Self-Hosted
dark mode light mode Search

Working with .NET, OpenOffice, and Mono

So I did hint as a work having to do with Mono I was commissioned. It’s actually a quite simple thing that by itself has no relationship with Mono, to be honest.

Basically, this friend of mine is self-employed, and sometimes has to prepare a budget for customers, to tell them how much a given service would cost them. I originally wrote such a software for him a few years ago, using Java, producing an HTML page that could be printed for the customers, and archived in a Firebird database. Unfortunately he lost the database and decided to not go with that since he preferred having the page published up in a different way to file down.

After an year without my software he decided that yeah it’s a good idea to have a database for this, and asked me to change the software around. Since he now runs on Vista, I’m tempted to use something different this time, something that also has a more suitable look and feel, which is one thing he complained about before, since the Java application didn’t look native. Of course the choice here is .NET, and as for how to handle the printed result, OpenOffice seems to have everything I need, I just need to generate a document with the right fields filled in, and then ask OpenOffice to convert it to PDF for filing or mailing, and so on so forth. The good thing is that he’s already using OpenOffice.

Now I just need to find how to interface with .NET (and Mono on Linux for development) to OpenOffice, and see if I can actually command it like I need it to. The alternative would be to create macros directly in OpenOffice, but I guess it’d be a bit of a mess for me to write code with that language, while C# I can work with quite nicely nowadays.

I guess that if I can make it generic enough, it’d be a nice thing to have around as Free Software, at least as a sample, I guess.

Comments 3
  1. http://www.artofsolving.com…JODConverter can be used in many different ways * As a Java library, embedded in your own Java application * As a command line tool, possibly invoked from your own scripts * As a simple web application: upload your input document, select the desired format and download the converted version * As a web service, invoked from your own application written in your favourite language (.NET, PHP, Python, Ruby, …)

  2. Hi mariuz,I want to do OpenOffice Automation with Browser so for that first I have create one test application in winform in that I have launched OpenOffice writer hide it then firnd it byProcessName and then i want to embed that launched OpenOffice writer in winform ,but while doing this I am not getting MainWindowHandle …… If u r getting me please help me what can I do now…..here is my codeusing System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Collections.ObjectModel;using System.Windows.Forms;using Microsoft.Win32;using OOLib;using System.Diagnostics;using System.Runtime.InteropServices;using unoidl.com.sun.star.uno;using unoidl.com.sun.star.lang;using unoidl.com.sun.star.frame;namespace Sample{public partial class Form1 : Form{private const int SW_SHOWNORMAL = 1;[DllImport(“user32.dll”)]public static extern bool ShowWindowAsync(IntPtr hWnd, int cmdShow);public ObservableCollection<oolib.officedocument> Docs { get; private set; }private OOLib.ServiceManager _ServiceManager = null;public OOLib.Desktop Desktop { get; private set; }private void Init(){if(_ServiceManager == null){_ServiceManager = new OOLib.ServiceManager();Desktop = _ServiceManager.CreateDesktop();}if(Desktop != null){var doc = Desktop.CreateTextDocument(hidden = true);Docs.Add(doc);}}private void Form1_Load(object sender, EventArgs e){}public Form1(){Docs = new ObservableCollection<oolib.officedocument>();InitializeComponent();}private static void FindOpenOffice(){try{Process[] ps = Process.GetProcessesByName(“soffice”);if(ps != null){if(ps.Length > 0)foreach(Process p in ps){// get mainwindow handle.//IntPtr pFoundWindow = Process.GetCurrentProcess().MainWindowHandle;//pFoundWindow getting nonzero value but all current process mainwindowHandleIntPtr pFoundWindow = p.MainWindowHandle;if(!pFoundWindow.Equals(IntPtr.Zero)){ShowWindowAsync(pFoundWindow, SW_SHOWNORMAL);}}}else{MessageBox.Show(“OpenOffice not found. Is OpenOffice installed?”);}}catch(System.Exception Exp){MessageBox.Show(Exp.Message);}}public bool hidden { get; set; }private void btnOpen_Click(object sender, EventArgs e){Init();FindOpenOffice();}}}

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.