Csharp/C#教程:Bootstrap Uno API LibreOfficeexception分享


Bootstrap Uno API LibreOfficeexception

使用以下代码:

static void Main() { try { var context = uno.util.Bootstrap.bootstrap(); } catch (Exception ex) { Console.WriteLine(ex.toString()); } } 

我可以开始LibreOffice的作家。 这适用于版本4.4.4但在安装版本5.0.0和新SDK后Bootstrap.bootstrap()抛出exception:

"External component has thrown an exception"

有没有人遇到同样的问题或一些解决方案? (.NET 4.0,Windows 7 64位,LibreOffice 5.0 Lite)

我已经设法通过在启动soffice.exe服务器之前设置UNO_PATH环境变量来解决此问题:

 using static System.Environment; var unoPath = @"C:Program FilesLibreOffice 5program" // 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 5program" SetEnvironmentVariable("UNO_PATH", unoPath, EnvironmentVariableTarget.Process); SetEnvironmentVariable("PATH", GetEnvironmentVariable("PATH") + @";" + unoPath, EnvironmentVariableTarget.Process); 

这是必需的,因为LibreOffice 5的程序目录不再具有UNO层所需的“URE”子目录(以前的版本)。

要获取LibreOffice安装的路径,您可以询问Windows注册表。 在C#中,这就像是:

  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(@"SOFTWARELibreOfficeUNOInstallPath", 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(@"SOFTWARELibreOfficeUNOInstallPath", false); if (hklmUnoInstallPathKey != null && hklmUnoInstallPathKey.ValueCount > 0) { unoPath = (string)hklmUnoInstallPathKey.GetValue(hklmUnoInstallPathKey.GetValueNames()[hklmUnoInstallPathKey.ValueCount - 1]); } } 

然后你可以使用Funbit的答案[ https://stackoverflow.com/a/31937114/2936206 ]

我找到的最简单的方法是将URE文件夹从之前的LibreOffice版本复制到LibreOffice 5。

上述就是C#学习教程:Bootstrap Uno API LibreOfficeexception分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)!

本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

ctvol管理联系方式QQ:251552304

本文章地址:https://www.ctvol.com/cdevelopment/941957.html

(0)
上一篇 2021年11月12日
下一篇 2021年11月12日

精彩推荐