| View previous topic :: View next topic |
| Author |
Message |
rs2.pt General User

Joined: 20 Oct 2008 Posts: 8
|
Posted: Wed Oct 22, 2008 3:27 am Post subject: Any simple demo how open a ODS file from C#,with Calc 3.0??? |
|
|
Hi all.
I am looking for a simple code sample that demos, using C# on VisualStudio for example, how to open an ODS file using OpenOffice 3.0 Calc !
why:
I have an application, that does that with OpenOffice 2.4.1
- It is a frontend on windows forms (using C# VisualStudio2008), that lets the user input values and calculate. The calculation is made on OOCalc using a ODS Calc file that has the formulas. All this works fine, the user even dont see the OO Calc app wich is hidden.
But with the new 3.0 OpenOffice the project wont work.
Initianly I had to replace new "cli" files and substitute the "cli_types.dll" that changed to "cli_oootypes.dll". After all, I had to copy the necessary new dlls from GAC (windows GlobaAssembyCache) to my project, so I could re-reference it again.
It compiles OK but I get an Exception when running that seems to be wen it tries to open(intialize) the Calc app...
Error:
"System.Runtime.InteropServices.SEHException: External component has thrown an exception.\r\n at cppu.bootstrap(Reference<com::sun::star::uno::XComponentContext>* )\r\n at uno.util.Bootstrap.bootstrap()\r\n at SiaccXpressOO.Form1..ctor() in D:\\WorkTFS\\OpenOfficeSandBox\\SiaccXpressOO\\Form1.cs:line 67"
in my line *
// get the remote office component context
* m_xContext = uno.util.Bootstrap.bootstrap();
MessageBox.Show("Connected to a running office ...");
...so, something to do with bootstrap.
Any simple example how to open a OpenOffice 3.0 file from a C# code...???
thanx |
|
| Back to top |
|
 |
Alain Rist General User

Joined: 07 Oct 2008 Posts: 18
|
Posted: Wed Oct 22, 2008 1:30 pm Post subject: Re: Any simple demo how open a ODS file from C#,with Calc 3. |
|
|
Hi,
| rs2.pt wrote: | | Any simple example how to open a OpenOffice 3.0 file from a C# code...??? |
I have a C++ routine which does that for a Win32 native app. Is it of interest to you?
cheers,
AR |
|
| Back to top |
|
 |
rs2.pt General User

Joined: 20 Oct 2008 Posts: 8
|
Posted: Thu Oct 23, 2008 12:34 am Post subject: Re: Any simple demo how open a ODS file from C#,with Calc 3. |
|
|
| Alain Rist wrote: | Hi,
| rs2.pt wrote: | | Any simple example how to open a OpenOffice 3.0 file from a C# code...??? |
I have a C++ routine which does that for a Win32 native app. Is it of interest to you?
cheers,
AR |
yes it could help, thanx.can you post here? |
|
| Back to top |
|
 |
Alain Rist General User

Joined: 07 Oct 2008 Posts: 18
|
Posted: Thu Oct 23, 2008 1:02 am Post subject: Re: Any simple demo how open a ODS file from C#,with Calc 3. |
|
|
| rs2.pt wrote: | | yes it could help, thanx.can you post here? |
| Code: | LRESULT FindInstallAndSetPath()
{
// Get the OpenOffice.org 3 installation key
static LPCWSTR sSubKey = L"SOFTWARE\\OpenOffice.org\\Layers\\URE\\1";
HKEY hk = NULL;
// check for user install
LRESULT lRes = ::RegOpenKeyEx(HKEY_CURRENT_USER, sSubKey, 0, KEY_READ, &hk);
if (!hk)
// check for machine install
lRes = ::RegOpenKeyEx(HKEY_LOCAL_MACHINE, sSubKey, 0, KEY_READ, &hk);
if (!hk)
return lRes;
// Allocate new PATH environment variable
PVOID pNewPath = calloc(MAX_PATH, sizeof(WCHAR));
if (!pNewPath)
return GetLastError();
// Get the UREINSTALLLOCATION directory
DWORD dwsize = MAX_PATH;
PWCHAR sNewPath = (PWCHAR)pNewPath;
if (lRes = RegQueryValueEx(hk, L"UREINSTALLLOCATION", NULL, NULL, (LPBYTE)sNewPath, &dwsize) == ERROR_SUCCESS)
lRes = wcsncat_s(sNewPath + wcslen(sNewPath), MAX_PATH - wcslen(sNewPath), L"bin;", 4);
RegCloseKey(hk);
// If failed
if FAILED(lRes)
{
free(pNewPath);
return lRes;
}
// Get the old PATH environment variable
size_t sizeOldPath;
lRes = _wgetenv_s(&sizeOldPath, NULL, 0, L"PATH");
LPWSTR sOldPath = (PWCHAR)malloc(sizeOldPath * sizeof(WCHAR));
if (sOldPath && SUCCEEDED(lRes))
lRes = _wgetenv_s(&sizeOldPath, sOldPath, sizeOldPath, L"PATH");
// Resize mem for new PATH environment variable
if (sNewPath = (PWCHAR)(pNewPath = realloc(pNewPath, (wcslen(sNewPath) + sizeOldPath) * sizeof(WCHAR))))
// Append old PATH content to new
if SUCCEEDED(lRes = wcsncat_s(sNewPath + wcslen(sNewPath), sizeOldPath, sOldPath, sizeOldPath))
// Change PATH environment variable
lRes = _wputenv_s(L"PATH", sNewPath);
// Cleanup
free(sOldPath);
free(pNewPath);
return lRes;
}
|
cheers,
AR |
|
| Back to top |
|
 |
parc Power User

Joined: 09 Nov 2007 Posts: 55 Location: Hamburg
|
Posted: Thu Oct 23, 2008 1:27 am Post subject: Re: Any simple demo how open a ODS file from C#,with Calc 3. |
|
|
I think, that is simply a problem in all OOo versions - I had this problem with 2.3.x, 2.4.x and now again with 3.0.0 versions (not on all systems - but the problem was there again and again on several systems). The main problem seems to be, that the bootloader needs additional libraries from the OOo installation - and it simply does not find them.
In the low-level code the developers of OOo seem to change the env. variable UNO_PATH and PATH to help the system finding the libraries they need. But for me (and another developer I'm in connection with) it simply does not work. Actually I've found no 3.0.0 system (up to now), where this works - and this means all our XP systems in our company.
There to get rid of these problems: I change the UNO_PATH variable and PATH variable myself BEFORE connecting to OOo.
Due to changed distribution directory layout my original patch for OOo 2.4 does not work for OOo 3.0.
The main steps are (if I recall it correctly):
Look for the value of "UREINSTALLLOCATION" within the windows registry at the node
"Software\OpenOffice.org\Layers\URE\1". Add "\bin" to that value and modify PATH to include that value - then it should work.
For source code you may look at: http://www.schrievkrom.de/blog/?p=199
Last edited by parc on Thu Oct 23, 2008 6:01 am; edited 1 time in total |
|
| Back to top |
|
 |
hro General User

Joined: 16 Sep 2008 Posts: 8
|
Posted: Thu Oct 23, 2008 5:44 am Post subject: |
|
|
I change the path in the registry and set the UNO_PATH but the error is still there.
I try to connect with OOconsoletest all the options failed with the same exception on the folowing line:
m_xContext = uno.util.Bootstrap.bootstrap();
Exception details:
L'exception System.Runtime.InteropServices.SEHException n'a pas été gérée
Message="External component has thrown an exception."
Source="cli_cppuhelper"
ErrorCode=-2147467259
StackTrace:
at cppu.bootstrap(Reference<com::sun::star::uno::XComponentContext>* )
at uno.util.Bootstrap.bootstrap()
at OOConsoleTest.Program.connect() in C:\Tmp\OOConsoleTest\OOConsoleTest\Program.cs:line 24
at OOConsoleTest.Program.ConnectToOpenOffice() in C:\Tmp\OOConsoleTest\OOConsoleTest\Program.cs:line 119
at OOConsoleTest.Program.Option01() in C:\Tmp\OOConsoleTest\OOConsoleTest\Program.cs:line 125
at OOConsoleTest.Program.ExecuteSwitch(Int16 selectedOption) in C:\Tmp\OOConsoleTest\OOConsoleTest\Program.cs:line 209
at OOConsoleTest.Program.Main(String[] args) in C:\Tmp\OOConsoleTest\OOConsoleTest\Program.cs:line 288
at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:
thanks for your help |
|
| Back to top |
|
 |
parc Power User

Joined: 09 Nov 2007 Posts: 55 Location: Hamburg
|
Posted: Thu Oct 23, 2008 6:01 am Post subject: |
|
|
| hro wrote: | | I change the path in the registry and set the UNO_PATH |
Change the PATH variable !!! My mistake !
Marten |
|
| Back to top |
|
 |
parc Power User

Joined: 09 Nov 2007 Posts: 55 Location: Hamburg
|
Posted: Thu Oct 23, 2008 6:10 am Post subject: |
|
|
Did you use my test program - under OO 3.0 you may only use the "option 07" to connect to OpenOffice. You do not have to change the PATH variable manually - leave that out.
I've talked with another person about this problem - and he simply reinstalled OO 3.0 and then "Option 07" worked. |
|
| Back to top |
|
 |
kasperih General User

Joined: 17 Oct 2008 Posts: 7
|
Posted: Thu Oct 23, 2008 11:21 am Post subject: |
|
|
Hi Parc
I downloaded your testapp and looks very promising. I was however wondering why the was only one cli dll file. The solution could not compile here, the cli_oootypes.dll and cli_uretypes didn't have any path. Where do you locate these 2 dll's? |
|
| Back to top |
|
 |
parc Power User

Joined: 09 Nov 2007 Posts: 55 Location: Hamburg
|
Posted: Thu Oct 23, 2008 12:22 pm Post subject: |
|
|
| kasperih wrote: | Hi Parc
I downloaded your testapp and looks very promising. I was however wondering why the was only one cli dll file. The solution could not compile here, the cli_oootypes.dll and cli_uretypes didn't have any path. Where do you locate these 2 dll's? |
I installed the OO 3.0 SDK and referenced the dll's from that (they are delivered with that). I do NOT deliver the dll's to "foreign" systems - because an installation of OO 3.0 stores them within the GAC and therefore the application should uses the already installed one. |
|
| Back to top |
|
 |
kasperih General User

Joined: 17 Oct 2008 Posts: 7
|
Posted: Thu Oct 23, 2008 9:44 pm Post subject: |
|
|
Hi Parc
I am making an application which produces pdf documents from odt documents. The odt documents are a part of the application but the open office installation has to be located on the PC where the application is installed.
Is it necessary to demand that all users of the application also download the SDK? How would you reference the necessary dll's when you do not know anything about the target machine? |
|
| Back to top |
|
 |
parc Power User

Joined: 09 Nov 2007 Posts: 55 Location: Hamburg
|
Posted: Thu Oct 23, 2008 10:15 pm Post subject: |
|
|
| kasperih wrote: | Hi Parc
I am making an application which produces pdf documents from odt documents. The odt documents are a part of the application but the open office installation has to be located on the PC where the application is installed.
Is it necessary to demand that all users of the application also download the SDK? How would you reference the necessary dll's when you do not know anything about the target machine? |
You as the developer only download the SDK. You develop against the "dll" included in the SDK. You may also use the dll from the GAC - but I find it more difficult to copy the files from that GAC.
You link your application against these dlls. You deliver your application without those dlls and when your application runs on your customers computers it try to load those dlls and gets them from the GAC. Fine.
I'm not clear how to get compatibility between 2.x.y OO installation and 3.x.y installations at this time, because the application based on OO 3.x.y must be recompiled, have other references and so on ....
On the other hand you must develop with the lowest OO system (2.4.0 or 3.0.0) you support at the customers. Developing with 2.4.1 is not a good idea, because 2.4.0 customers might get problems ... |
|
| Back to top |
|
 |
hro General User

Joined: 16 Sep 2008 Posts: 8
|
Posted: Fri Oct 24, 2008 12:33 am Post subject: |
|
|
Thank you very much "parc". With your advise I can now execute properly my application with OOo 3.0 CLI API.
To recapitulate :
1) Change the regsitry key HKEY_LOCAL_MACHINE\SOFTWARE\OpenOffice.org\Layers\URE\1UREINSTALLLOCATION to C:\Program Files\OpenOffice.org 3\URE\bin
2) Add the OpenOffice installation path (C:\Program Files\OpenOffice.org 3\program) to the PATH variable. |
|
| Back to top |
|
 |
parc Power User

Joined: 09 Nov 2007 Posts: 55 Location: Hamburg
|
Posted: Fri Oct 24, 2008 2:15 am Post subject: |
|
|
| hro wrote: | Thank you very much "parc". With your advise I can now execute properly my application with OOo 3.0 CLI API.
To recapitulate :
1) Change the regsitry key HKEY_LOCAL_MACHINE\SOFTWARE\OpenOffice.org\Layers\URE\1UREINSTALLLOCATION to C:\Program Files\OpenOffice.org 3\URE\bin
2) Add the OpenOffice installation path (C:\Program Files\OpenOffice.org 3\program) to the PATH variable. |
No, no do NOT change the content of the registry key.
modify UNO_PATH to something like "C:\Program Files\OpenOffice.org 3\program" (via registry >key Software\OpenOffice.org\UNO\InstallPath>
modify PATH to include something like "C:\Program Files\OpenOffice.org 3\URE\bin"
(via registry key <Software\OpenOffice.org\Layers\URE\1>)
And then after all you have to consider HKEY_LOCAL_MACHINE and HKEY_CURRENT_USER. In both parts of the registry you might find the keys you are looking for.
Under OO 2.4.x it was different: there PATH had to be modified to include something like "C:\Program Files\OpenOffice.org 3\program".
But after all: Both OO 2.x and OO 3.x and cli should work without these patches ... but actually they have lots of problems.
Hope, that this is now clear ?? |
|
| Back to top |
|
 |
kasperih General User

Joined: 17 Oct 2008 Posts: 7
|
Posted: Sun Oct 26, 2008 11:55 pm Post subject: |
|
|
Hi Parc
Thank you very much my application is working fine now. |
|
| Back to top |
|
 |
|