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)中,您可以添加带有指向这些组件的适当提示的参考条目。例如,您可能会添加类似的内容:
此外,请确保您的运行时可以找到本机库。您可能需要更新
<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进行交互。