[Solved] C#, using OOo, problem

Java, C++, C#, Delphi... - Using the UNO bridges
Post Reply
Ijacek
Posts: 2
Joined: Tue Jul 27, 2010 9:42 am

[Solved] C#, using OOo, problem

Post by Ijacek »

Please help me, Im realy frustrated :crazy: !
I'm trying to use OOo 3.2 in C# code (with Visual Studio 2010 Express). I have read many articles (but I'm newbie in this subject, so its difficult to me). Finally I have written some code (using SDK because in OOo I haven't found cli_* files).

Code:


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using unoidl.com.sun.star.lang;
using unoidl.com.sun.star.uno;
using unoidl.com.sun.star.bridge;
using unoidl.com.sun.star.frame;
using unoidl.com.sun.star.text;
using unoidl.com.sun.star.beans;
using unoidl.com.sun.star.sheet;
using unoidl.com.sun.star.container;
using unoidl.com.sun.star.table;


namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
XComponentContext oStrap = uno.util.Bootstrap.bootstrap();
XMultiServiceFactory oServMan = (XMultiServiceFactory)oStrap.getServiceManager();
XComponentLoader oDesk = (XComponentLoader)oServMan.createInstance("com.sun.star.frame.Desktop");
string url = @"private:factory/scalc";
PropertyValue[] propVals = new PropertyValue[0];
XComponent oDoc = oDesk.loadComponentFromURL(url, "_blank", 0, propVals);
XSpreadsheets oSheets = ((XSpreadsheetDocument)oDoc).getSheets();
XIndexAccess oSheetsIA = (XIndexAccess)oSheets;
XSpreadsheet oSheet = (XSpreadsheet)oSheetsIA.getByIndex(0).Value;
XCell oCell = oSheet.getCellByPosition(0, 0); //A1
((XText)oCell).setString("Cost");
oCell = oSheet.getCellByPosition(1, 0); //B1
oCell.setValue(200);
oCell = oSheet.getCellByPosition(1, 2); //B3
oCell.setFormula("=B1 * 1.175");

string fileName = @"vat.ods";
((XStorable)oDoc).storeAsURL(fileName, propVals);
oDoc.dispose();
oDoc = null;

}
}
}

The result was:

Error: FileLoadException was unhandled:
Mixed mode assembly is built against version 'v2.0.50727' of the runtime and cannot be loaded in the 4.0 runtime without additional configuration information.

I don't know what does it mean and how to manage it. Where is problem?
Please, please could someone help me?


************************************************************************************************************************************************
AS USUAL SOLUTION WAS VERY EASY: switch to .NET v 2 in properties of project!!!!!!!!!!!!!!!!!!
************************************************************************************************************************************************
OOo 3.2, Windows 7, Windows XP, Ubuntu 10.4
jTyma
Posts: 1
Joined: Tue Mar 15, 2011 11:32 am

Re: [Solved] C#, using OOo, problem

Post by jTyma »

I have the same problem :(

I solved it that I add to app.config this code:

<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0" />
</startup>

Jaroslav Týma
OpenOffice 3.2 on Windows XP
Post Reply