using System;
using System.Collections. Generic ;
using System.Text;
using System.Drawing;
using System.IO;
//OOo 3
using unoidl.com.sun.star.lang;
using UNO = unoidl.com.sun.star.uno;
using unoidl.com.sun.star.bridge;
using unoidl.com.sun.star.frame;
using OOo = unoidl.com.sun.star;
using Microsoft.Win32;
using System.Runtime.InteropServices;
* This source code was highlighted with Source Code Highlighter .
private void InitOO3Env()
{
string baseKey = "" ;
if (Marshal.SizeOf( typeof ( IntPtr )) == 8) baseKey = @"SOFTWARE\Wow6432Node\OpenOffice.org\" ;
else
baseKey = @"SOFTWARE\OpenOffice.org\" ;
// Get the URE directory
string key = baseKey + @"Layers\URE\1" ;
RegistryKey reg = Registry.CurrentUser.OpenSubKey(key);
if (reg == null ) reg = Registry.LocalMachine.OpenSubKey(key);
string urePath = reg.GetValue( "UREINSTALLLOCATION" ) as string ;
reg.Close();
urePath = Path.Combine(urePath, "bin" );
// Get the UNO Path
key = baseKey + @"UNO\InstallPath" ;
reg = Registry.CurrentUser.OpenSubKey(key);
if (reg == null ) reg = Registry.LocalMachine.OpenSubKey(key);
string unoPath = reg.GetValue( null ) as string ;
reg.Close();
string path;
string sysPath = System.Environment.GetEnvironmentVariable( "PATH" );
path = string .Format( "{0};{1}" , System.Environment.GetEnvironmentVariable( "PATH" ), urePath);
System.Environment.SetEnvironmentVariable( "PATH" , path);
System.Environment.SetEnvironmentVariable( "UNO_PATH" , unoPath);
}
* This source code was highlighted with Source Code Highlighter .
// ?
private bool isOOoInstalled()
{
string baseKey;
// 64
if (Marshal.SizeOf( typeof ( IntPtr )) == 8) baseKey = @"SOFTWARE\Wow6432Node\OpenOffice.org\" ;
else
baseKey = @"SOFTWARE\OpenOffice.org\" ;
string key = baseKey + @"Layers\URE\1" ;
RegistryKey reg = Registry.CurrentUser.OpenSubKey(key);
if (reg == null ) reg = Registry.LocalMachine.OpenSubKey(key);
string urePath = reg.GetValue( "UREINSTALLLOCATION" ) as string ;
reg.Close();
if (urePath != null ) return true ;
else
return false ;
}
// ( \ )
private OOo.lang.XMultiServiceFactory uno_connect( String [] args)
{
InitOO3Env();
unoidl.com.sun.star.uno.XComponentContext m_xContext m_xContext = uno.util.Bootstrap.bootstrap();
if (m_xContext != null )
return (OOo.lang.XMultiServiceFactory)m_xContext.getServiceManager();
else
return null ;
}
// \ Calc
private unoidl.com.sun.star.sheet.XSpreadsheetDocument OOo3_initCalcDocument( string filePath, bool newDoc)
{
XComponentLoader aLoader;
XComponent xComponent = null ;
string url = newDoc ? "private:factory/scalc" : @"file:///" + filePath.Replace( @"\" , @"/" );
try
{
aLoader = (XComponentLoader)
mxMSFactory.createInstance( "com.sun.star.frame.Desktop" );
xComponent = aLoader.loadComponentFromURL(
/*"private:factory/scalc"*/ url, "_blank" , 0,
new unoidl.com.sun.star.beans.PropertyValue[0]);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
return (OOo.sheet.XSpreadsheetDocument)xComponent;
}
// \ Writer
private OOo.text.XTextDocument OOo3_initWriterDocument ( string filePath, bool newDoc)
{
XComponentLoader aLoader;
XComponent xComponent = null ;
string url = newDoc? "Private: factory / swriter" : @ "file: ///" + filePath.Replace ( @ "\" , @ "/" );
try
{
aLoader = (XComponentLoader)
mxMSFactory.createInstance ( "com.sun.star.frame.Desktop" );
xComponent = aLoader.loadComponentFromURL (
url, "_blank" , 0,
new unoidl.com.sun.star.beans.PropertyValue [0]);
}
catch (Exception ex)
{
MessageBox.Show (ex.Message);
}
return (OOo.text.XTextDocument) xComponent;
}
Source: https://habr.com/ru/post/49373/
All Articles