如何在debian上使用.net 8中使用libreoffice uno api?

问题描述 投票:0回答:1
I是在Debian上开发.NET 8跨平台应用程序,该应用需要通过UNO API与Libreoffice进行交互。我要完成的是保存打开的libre Office选项卡。 我的大约代码是:

using unoidl.com.sun.star.frame; using unoidl.com.sun.star.lang; using unoidl.com.sun.star.uno; using unoidl.com.sun.star.beans; public void SaveLibreOfficeDocument() { XComponentContext xLocalContext = uno.util.Bootstrap.bootstrap(); XMultiComponentFactory xMCF = xLocalContext.getServiceManager(); object desktop = xMCF.createInstanceWithContext("com.sun.star.frame.Desktop", xLocalContext); XComponentLoader xCL = (XComponentLoader)desktop; XModel xModel = (XModel)xCL.loadComponentFromURL("private:factory/scalc", "_blank", 0, new PropertyValue[0]); XStorable xStorable = (XStorable)xModel; xStorable.store(); }

问题是我真的不知道如何包含所有这些软件包(
using
被突出显示为错误)。

您需要在您的.NET项目中包括Libreoffice提供的UNO API库,因为没有官方的Nuget软件包。从本质上讲,在Debian系统上安装了Libreoffice(以及理想情况下是Libreoffice SDK)之后,您必须将Libreoffice安装的UNO组装添加到Cli_Basetypes,Cli_cppuhelper,Cli_ure,Cli_uno和Cli_uno,以及Cli_uno -From -from libreoff conigner(典型)(典型)(典型)(典型)。
在您的项目文件(.csproj)中,您可以添加带有指向这些组件的适当提示的参考条目。例如,您可能会添加类似的内容:

c# .net linux openoffice.org uno
1个回答
0
投票

此外,请确保您的运行时可以找到本机库。您可能需要更新

<ItemGroup>
  <Reference Include="cli_uno">
    <HintPath>/usr/lib/libreoffice/program/cli_uno.dll</HintPath>
  </Reference>
  <Reference Include="cli_ure">
    <HintPath>/usr/lib/libreoffice/program/cli_ure.dll</HintPath>
  </Reference>
  <!-- add other required UNO assemblies similarly -->
</ItemGroup>
环境变量以包含

LD_LIBRARY_PATH

,以便在运行时可以找到任何因本机库。一旦添加了这些引用,您的代码(使用

/usr/lib/libreoffice/program
获取组件上下文)应能够通过UNO API与Libreoffice进行交互。
    

© www.soinside.com 2019 - 2025. All rights reserved.