Bootstrap Uno API LibreOffice exception

泪湿孤枕 提交于 2019-12-01 19:27:21
Funbit

I have managed to solve the problem by setting the UNO_PATH environment variable before starting the soffice.exe server:

using static System.Environment;

var unoPath = @"C:\Program Files\LibreOffice 5\program"
// when running 32-bit LibreOffice on a 64-bit system, the path will be in Program Files (x86)
// var unoPath = @"C:\Program Files (x86)\LibreOffice 5\program"

SetEnvironmentVariable("UNO_PATH", unoPath, EnvironmentVariableTarget.Process);
SetEnvironmentVariable("PATH", GetEnvironmentVariable("PATH") + @";" + unoPath, EnvironmentVariableTarget.Process);

This was required because LibreOffice 5's program directory does not have "URE" subdirectory anymore (previous versions did) which is required for UNO layer.

Jens Bornschein

To get the path to the LibreOffice installation you can ask e.g. the Windows registry. In C# this is smoething like that:

    String unoPath = "";
    // access 32bit registry entry for latest LibreOffice for Current User
    Microsoft.Win32.RegistryKey hkcuView32 = Microsoft.Win32.RegistryKey.OpenBaseKey(Microsoft.Win32.RegistryHive.CurrentUser, Microsoft.Win32.RegistryView.Registry32);
    Microsoft.Win32.RegistryKey hkcuUnoInstallPathKey = hkcuView32.OpenSubKey(@"SOFTWARE\LibreOffice\UNO\InstallPath", false);
    if (hkcuUnoInstallPathKey != null && hkcuUnoInstallPathKey.ValueCount > 0)
    {
        unoPath = (string)hkcuUnoInstallPathKey.GetValue(hkcuUnoInstallPathKey.GetValueNames()[hkcuUnoInstallPathKey.ValueCount - 1]);
    }
    else
    {
        // access 32bit registry entry for latest LibreOffice for Local Machine (All Users)
        Microsoft.Win32.RegistryKey hklmView32 = Microsoft.Win32.RegistryKey.OpenBaseKey(Microsoft.Win32.RegistryHive.LocalMachine, Microsoft.Win32.RegistryView.Registry32);
        Microsoft.Win32.RegistryKey hklmUnoInstallPathKey = hklmView32.OpenSubKey(@"SOFTWARE\LibreOffice\UNO\InstallPath", false);
        if (hklmUnoInstallPathKey != null && hklmUnoInstallPathKey.ValueCount > 0)
        {
            unoPath = (string)hklmUnoInstallPathKey.GetValue(hklmUnoInstallPathKey.GetValueNames()[hklmUnoInstallPathKey.ValueCount - 1]);
        }
    }

Then you can use the answer of Funbit [ https://stackoverflow.com/a/31937114/2936206 ]

The most easiest way I found is just copy the URE folder from previous LibreOffice version to LibreOffice 5.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!